lowdown 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f620c2ee4c30e758aa31e08f573294917fe7775
4
- data.tar.gz: 8e3aaee822bb87030d499cfa0fb08e62cdc7bae1
3
+ metadata.gz: cac86340acb40e426c4d36fe8b65f6d023166293
4
+ data.tar.gz: 645fdfd12c742e514b7613f3283da11141c08d17
5
5
  SHA512:
6
- metadata.gz: 58e48b9f6708027adb8461a5fe73767a8f375475390a136d9b34635482825dc83a5f16a79541b0c052b0454d77ef3f1bdd5f766b946d94b202bd84c2e9a53b08
7
- data.tar.gz: 07f3a6bbd79d25d05d94dc03465ffef5fed298866682f003f888b8f40cfe8d80a5c9f5b540e914c95abca1145cfc290946afd53c34ff45eeab8fd9d546768323
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
@@ -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 = [:alert, :badge, :sound, :content_available, :category].freeze
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?(:aps)
25
+ if @payload.has_key?("aps")
26
26
  @payload
27
27
  else
28
28
  payload = {}
29
- payload[:aps] = aps = {}
29
+ payload["aps"] = aps = {}
30
30
  @payload.each do |key, value|
31
- key = key.to_sym
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
@@ -1,3 +1,3 @@
1
1
  module Lowdown
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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