lowdown 0.0.2 → 0.0.3
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 +4 -4
- data/lib/lowdown/connection/mock.rb +57 -0
- data/lib/lowdown/notification.rb +5 -4
- data/lib/lowdown/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac86340acb40e426c4d36fe8b65f6d023166293
|
4
|
+
data.tar.gz: 645fdfd12c742e514b7613f3283da11141c08d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d46552ff47566b8efe60b8684151e0f443468bab5175446d9853ce868640d1ace5364f19ce6cef8c05118be94136d58ffc7d901b5fb303b0cee26e29f28e2960
|
7
|
+
data.tar.gz: 47cee9254108a7b687a50e437ef4adf7c49d243c552516131fc5764a38843b68b79597a4fa0a705c7557d958a44e75b3df393384682feb2417a8e3f1b7c6709f
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "lowdown/response"
|
2
|
+
|
3
|
+
module Lowdown
|
4
|
+
class Connection
|
5
|
+
class Mock
|
6
|
+
Request = Struct.new(:path, :headers, :body, :response)
|
7
|
+
|
8
|
+
attr_reader :requests, :responses
|
9
|
+
|
10
|
+
def initialize(responses = [])
|
11
|
+
@responses = responses
|
12
|
+
@requests = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def requests_as_notifications(unformatted_id_length = nil)
|
16
|
+
@requests.map do |request|
|
17
|
+
headers = request.headers
|
18
|
+
hash = {
|
19
|
+
:token => File.basename(request.path),
|
20
|
+
:id => request.response.unformatted_id(unformatted_id_length),
|
21
|
+
:payload => JSON.parse(request.body),
|
22
|
+
:topic => headers["apns-topic"]
|
23
|
+
}
|
24
|
+
hash[:expiration] = Time.at(headers["apns-expiration"].to_i) if headers["apns-expiration"]
|
25
|
+
hash[:priority] = headers["apns-priority"].to_i if headers["apns-priority"]
|
26
|
+
Notification.new(hash)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def post(path, headers, body)
|
31
|
+
response = @responses.shift || Response.new(":status" => "200", "apns-id" => (headers["apns-id"] || generate_id))
|
32
|
+
@requests << Request.new(path, headers, body, response)
|
33
|
+
yield response
|
34
|
+
end
|
35
|
+
|
36
|
+
def open
|
37
|
+
@open = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
@open = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def open?
|
45
|
+
!!@open
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def generate_id
|
51
|
+
@counter ||= 0
|
52
|
+
@counter += 1
|
53
|
+
Notification.new(:id => @counter).formatted_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/lowdown/notification.rb
CHANGED
@@ -2,7 +2,7 @@ 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 =
|
5
|
+
APS_KEYS = %w{ alert badge sound content-available category }.freeze
|
6
6
|
|
7
7
|
attr_accessor :token, :id, :expiration, :priority, :topic, :payload
|
8
8
|
|
@@ -22,13 +22,14 @@ module Lowdown
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def formatted_payload
|
25
|
-
if @payload.has_key?(
|
25
|
+
if @payload.has_key?("aps")
|
26
26
|
@payload
|
27
27
|
else
|
28
28
|
payload = {}
|
29
|
-
payload[
|
29
|
+
payload["aps"] = aps = {}
|
30
30
|
@payload.each do |key, value|
|
31
|
-
|
31
|
+
next if value.nil?
|
32
|
+
key = key.to_s
|
32
33
|
if APS_KEYS.include?(key)
|
33
34
|
aps[key] = value
|
34
35
|
else
|
data/lib/lowdown/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lowdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Durán
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/lowdown/certificate.rb
|
87
87
|
- lib/lowdown/client.rb
|
88
88
|
- lib/lowdown/connection.rb
|
89
|
+
- lib/lowdown/connection/mock.rb
|
89
90
|
- lib/lowdown/notification.rb
|
90
91
|
- lib/lowdown/response.rb
|
91
92
|
- lib/lowdown/threading.rb
|