Module apns_connection

This gen_statem handles the APNs Connection.

Copyright © Inaka <hello@inaka.net>

Behaviours: gen_statem.

Description

This gen_statem handles the APNs Connection.

Copyright 2017 Erlang Solutions Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Data Types

connection()

connection() = #{name := name(), apple_host := host(), apple_port := inet:port_number(), certdata => binary(), certfile => path(), keydata => keydata(), keyfile => path(), timeout => integer(), type := type(), proxy_info => proxy_info()}

host()

host() = string() | inet:ip_address()

keydata()

keydata() = {'RSAPrivateKey' | 'DSAPrivateKey' | 'ECPrivateKey' | 'PrivateKeyInfo', binary()}

name()

name() = atom()

notification()

notification() = binary()

path()

path() = string()

proxy_info()

proxy_info() = #{type := connect, host := host(), port := inet:port_number(), username => iodata(), password => iodata()}

state()

state() = #{connection := connection(), gun_pid => pid(), gun_monitor => reference(), gun_connect_ref => reference(), client := pid(), backoff := non_neg_integer(), backoff_ceiling := non_neg_integer()}

type()

type() = certdata | cert | token

Function Index

await_tunnel_up/3
await_up/3
callback_mode/0
certdata/1
certfile/1
close_connection/1Close the connection with APNs gracefully.
code_change/4
connected/3
default_connection/2Builds a connection() map from the environment variables.
down/3
gun_pid/1Returns the gun's connection PID.
host/1
init/1
keydata/1
keyfile/1
name/1
open_common/3
open_connection/3
open_origin/3
open_proxy/3
port/1
proxy_connect_to_origin/3
push_notification/4Pushes notification to certificate APNs connection.
push_notification/5Pushes notification to certificate APNs connection.
start_link/2starts the gen_statem.
type/1
wait_apns_connection_up/1Waits until the APNS connection is up.

Function Details

await_tunnel_up/3

await_tunnel_up(EventType::term(), EventContent::term(), StateData::term()) -> term()

await_up/3

await_up(EventType::term(), EventContent::term(), StateData::term()) -> term()

callback_mode/0

callback_mode() -> state_functions

certdata/1

certdata(X1::connection()) -> binary()

certfile/1

certfile(X1::connection()) -> path()

close_connection/1

close_connection(ConnectionId::name() | pid()) -> ok

Close the connection with APNs gracefully

code_change/4

code_change(OldVsn::term() | {down, term()}, StateName, StateData, Extra::term()) -> {ok, StateName, StateData}

connected/3

connected(EventType::term(), Event::term(), StateData::term()) -> term()

default_connection/2

default_connection(X1::type(), ConnectionName::name()) -> connection()

Builds a connection() map from the environment variables.

down/3

down(EventType::term(), EventContent::term(), StateData::term()) -> term()

gun_pid/1

gun_pid(ConnectionId::name() | pid()) -> pid()

Returns the gun's connection PID. This function is only used in tests.

host/1

host(X1::connection()) -> host()

init/1

init(X1::{connection(), pid()}) -> {ok, open_connection, State::state(), {next_event, internal, init}}

keydata/1

keydata(X1::connection()) -> keydata()

keyfile/1

keyfile(X1::connection()) -> path()

name/1

name(X1::connection()) -> name()

open_common/3

open_common(X1::term(), X2::term(), StateData::term()) -> term()

open_connection/3

open_connection(X1::term(), X2::term(), StateData::term()) -> term()

open_origin/3

open_origin(X1::term(), X2::term(), StateData::term()) -> term()

open_proxy/3

open_proxy(X1::term(), X2::term(), StateData::term()) -> term()

port/1

port(X1::connection()) -> inet:port_number()

proxy_connect_to_origin/3

proxy_connect_to_origin(X1::term(), X2::term(), StateData::term()) -> term()

push_notification/4

push_notification(ConnectionId::name() | pid(), DeviceId::apns:device_id(), Notification::notification(), Headers::apns:headers()) -> apns:response() | {error, not_connection_owner}

Pushes notification to certificate APNs connection.

push_notification/5

push_notification(ConnectionId::name() | pid(), Token::apns:token(), DeviceId::apns:device_id(), Notification::notification(), Headers::apns:headers()) -> apns:response() | {error, not_connection_owner}

Pushes notification to certificate APNs connection.

start_link/2

start_link(Connection::connection(), Client::pid()) -> {ok, Pid::pid()} | ignore | {error, Reason::term()}

starts the gen_statem

type/1

type(X1::connection()) -> type()

wait_apns_connection_up/1

wait_apns_connection_up(Server::pid()) -> ok

Waits until the APNS connection is up.

Note that this function does not need to be called before sending push notifications, since they will be queued up and sent when the connection is established.


Generated by EDoc