Class: Lowdown::Connection::Mock
- Inherits:
-
Object
- Object
- Lowdown::Connection::Mock
- Defined in:
- lib/lowdown/connection/mock.rb
Defined Under Namespace
Classes: Request
Instance Attribute Summary collapse
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(responses = []) ⇒ Mock
constructor
A new instance of Mock.
- #open ⇒ Object
- #open? ⇒ Boolean
- #post(path, headers, body) {|response| ... } ⇒ Object
- #requests_as_notifications(unformatted_id_length = nil) ⇒ Object
Constructor Details
#initialize(responses = []) ⇒ Mock
Returns a new instance of Mock.
10 11 12 13 |
# File 'lib/lowdown/connection/mock.rb', line 10 def initialize(responses = []) @responses = responses @requests = [] end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
8 9 10 |
# File 'lib/lowdown/connection/mock.rb', line 8 def requests @requests end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
8 9 10 |
# File 'lib/lowdown/connection/mock.rb', line 8 def responses @responses end |
Instance Method Details
#close ⇒ Object
40 41 42 |
# File 'lib/lowdown/connection/mock.rb', line 40 def close @open = false end |
#open ⇒ Object
36 37 38 |
# File 'lib/lowdown/connection/mock.rb', line 36 def open @open = true end |
#open? ⇒ Boolean
44 45 46 |
# File 'lib/lowdown/connection/mock.rb', line 44 def open? !!@open end |
#post(path, headers, body) {|response| ... } ⇒ Object
30 31 32 33 34 |
# File 'lib/lowdown/connection/mock.rb', line 30 def post(path, headers, body) response = @responses.shift || Response.new(":status" => "200", "apns-id" => (headers["apns-id"] || generate_id)) @requests << Request.new(path, headers, body, response) yield response end |
#requests_as_notifications(unformatted_id_length = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lowdown/connection/mock.rb', line 15 def requests_as_notifications(unformatted_id_length = nil) @requests.map do |request| headers = request.headers hash = { :token => File.basename(request.path), :id => request.response.unformatted_id(unformatted_id_length), :payload => JSON.parse(request.body), :topic => headers["apns-topic"] } hash[:expiration] = Time.at(headers["apns-expiration"].to_i) if headers["apns-expiration"] hash[:priority] = headers["apns-priority"].to_i if headers["apns-priority"] Notification.new(hash) end end |