lowdown 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 596c18a9090845d35a4395a928c71c3b0c493f63
4
- data.tar.gz: 2003c1226c6d4f1831452f1b83c5a2caeb0d38cc
3
+ metadata.gz: 4f620c2ee4c30e758aa31e08f573294917fe7775
4
+ data.tar.gz: 8e3aaee822bb87030d499cfa0fb08e62cdc7bae1
5
5
  SHA512:
6
- metadata.gz: 11c94276f939853a735caae9b90a50ca288c6a9d77a070d5b5be8d5c7f401afefc0ce8a94ec249266bf10ad6d8cf92065fd91d3e8dfbd3e7295d3ffec741755a
7
- data.tar.gz: 0652004863baf52a637f207243e1b2b891da389e6995565717378015efaf9eb12e40e83b7a73ff7e4a715c057e0e1599b4580f3e77b5e6d3b941434a27707180
6
+ metadata.gz: 58e48b9f6708027adb8461a5fe73767a8f375475390a136d9b34635482825dc83a5f16a79541b0c052b0454d77ef3f1bdd5f766b946d94b202bd84c2e9a53b08
7
+ data.tar.gz: 07f3a6bbd79d25d05d94dc03465ffef5fed298866682f003f888b8f40cfe8d80a5c9f5b540e914c95abca1145cfc290946afd53c34ff45eeab8fd9d546768323
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Lowdown is a Ruby client for the HTTP/2 version of the Apple Push Notification Service.
4
4
 
5
+ Multiple notifications are multiplexed for efficiency.
6
+
7
+ NOTE: _It is not yet battle-tested and there is no documentation yet. This will all follow over the next few weeks._
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -20,7 +24,7 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
23
- You can use the `lowdown` bin that comes with this gem or in code at it’s simplest:
27
+ You can use the `lowdown` bin that comes with this gem or in code at its simplest:
24
28
 
25
29
  ```ruby
26
30
  notification = Lowdown::Notification.new(:token => "device-token", :payload => { :alert => "Hello World!" })
@@ -65,7 +65,7 @@ module Lowdown
65
65
  headers["apns-priority"] = notification.priority if notification.priority
66
66
  headers["apns-topic"] = topic if topic
67
67
 
68
- body = { :aps => notification.payload }.to_json
68
+ body = notification.formatted_payload.to_json
69
69
 
70
70
  @connection.post("/3/device/#{notification.token}", headers, body, &callback)
71
71
  end
@@ -2,6 +2,8 @@ module Lowdown
2
2
  # For payload documentation see: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1
3
3
  #
4
4
  class Notification
5
+ APS_KEYS = [:alert, :badge, :sound, :content_available, :category].freeze
6
+
5
7
  attr_accessor :token, :id, :expiration, :priority, :topic, :payload
6
8
 
7
9
  def initialize(params)
@@ -18,5 +20,23 @@ module Lowdown
18
20
  [padded[0,8], padded[8,4], padded[12,4], padded[16,4], padded[20,12]].join("-")
19
21
  end
20
22
  end
23
+
24
+ def formatted_payload
25
+ if @payload.has_key?(:aps)
26
+ @payload
27
+ else
28
+ payload = {}
29
+ payload[:aps] = aps = {}
30
+ @payload.each do |key, value|
31
+ key = key.to_sym
32
+ if APS_KEYS.include?(key)
33
+ aps[key] = value
34
+ else
35
+ payload[key] = value
36
+ end
37
+ end
38
+ payload
39
+ end
40
+ end
21
41
  end
22
42
  end
@@ -1,3 +1,3 @@
1
1
  module Lowdown
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Durán
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-31 00:00:00.000000000 Z
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2