Class: ApnsGatling::Response
- Inherits:
-
Object
- Object
- ApnsGatling::Response
- Defined in:
- lib/apns_gatling/response.rb
Instance Attribute Summary collapse
- #data ⇒ Object
- #headers ⇒ Object
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #error ⇒ Object
- #error_with(reason) ⇒ Object
-
#initialize(message) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #parse_data ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(message) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 |
# File 'lib/apns_gatling/response.rb', line 9 def initialize() @headers = {} @data = '' @message = @internal_error = nil end |
Instance Attribute Details
#data ⇒ Object
6 7 8 |
# File 'lib/apns_gatling/response.rb', line 6 def data @data end |
#headers ⇒ Object
6 7 8 |
# File 'lib/apns_gatling/response.rb', line 6 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/apns_gatling/response.rb', line 7 def @message end |
Instance Method Details
#error ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/apns_gatling/response.rb', line 32 def error return @internal_error if @internal_error if status != '200' e = {} e.merge!(status: @headers[':status']) if @headers[':status'] e.merge!('apns-id' => @headers['apns-id']) if @headers['apns-id'] data = parse_data e.merge!(reason: data['reason']) if data['reason'] e.merge!(timestamp: data['timestamp']) if data['timestamp'] e end end |
#error_with(reason) ⇒ Object
28 29 30 |
# File 'lib/apns_gatling/response.rb', line 28 def error_with(reason) @internal_error = {reason: reason, 'apns-id': @message.apns_id, status: '0'} end |
#ok? ⇒ Boolean
20 21 22 |
# File 'lib/apns_gatling/response.rb', line 20 def ok? status == '200' end |
#parse_data ⇒ Object
24 25 26 |
# File 'lib/apns_gatling/response.rb', line 24 def parse_data JSON.parse(@data) rescue @data end |
#status ⇒ Object
16 17 18 |
# File 'lib/apns_gatling/response.rb', line 16 def status @headers[':status'] if @headers end |