Skip to content

Commit

Permalink
Add ping feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rslota committed Mar 7, 2017
1 parent 1bf81a6 commit 087bb38
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 146 deletions.
9 changes: 7 additions & 2 deletions lib/pigeon/apns_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Pigeon.APNSWorker do
@moduledoc """
Handles all APNS request and response parsing over an HTTP2 connection.
"""
use Pigeon.GenericH2Worker
use Pigeon.GenericH2Worker, ping_interval: 600_000
require Logger

def host(config) do
Expand All @@ -19,6 +19,10 @@ defmodule Pigeon.APNSWorker do
end
end

def encode_notification(notification) do
Pigeon.Notification.json_payload(notification.payload)
end

def socket_options(config) do
cert = get_opt(config, :cert, :certfile)
key = get_opt(config, :key, :keyfile)
Expand All @@ -43,7 +47,8 @@ defmodule Pigeon.APNSWorker do
end

def req_headers(_config, notification) do
[]
[{"content-type", "application/json"},
{"accept", "application/json"}]
|> put_apns_id(notification)
|> put_apns_topic(notification)
end
Expand Down
16 changes: 11 additions & 5 deletions lib/pigeon/gcm_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Pigeon.GCMWorker do
@moduledoc """
Handles all FCM request and response parsing over an HTTP2 connection.
"""
use Pigeon.GenericH2Worker
use Pigeon.GenericH2Worker, ping_interval: 60_000
alias Pigeon.GCM.NotificationResponse
require Logger

Expand All @@ -17,11 +17,17 @@ defmodule Pigeon.GCMWorker do
end

def socket_options(_config) do
[]
{:ok, []}
end

def encode_notification({_registration_ids, notification}) do
notification
end

def req_headers(config, _notification) do
[{"authorization", "key=#{config[:key]}"}]
[{"authorization", "key=#{config[:key]}"},
{"content-type", "application/json"},
{"accept", "application/json"}]
end

def req_path(_notification) do
Expand All @@ -33,9 +39,9 @@ defmodule Pigeon.GCMWorker do
response["reason"] |> Macro.underscore |> String.to_existing_atom
end

defp parse_response(notification, _headers, body) do
defp parse_response({registration_ids, payload}, _headers, body) do
result = Poison.decode! body
parse_result(notification.registration_ids, result)
parse_result(registration_ids, result)
end

def parse_result(ids, %{"results" => results}) do
Expand Down
Loading

0 comments on commit 087bb38

Please sign in to comment.