Class: Lorkhan::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/lorkhan/response.rb

Overview

A wrapper around the HTTP/2 response from Apple

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

This class should never be instantiated directly.



11
12
13
14
15
16
# File 'lib/lorkhan/response.rb', line 11

def initialize(raw)
  @headers = raw.headers
  @body    = JSON.parse(raw.body)
rescue JSON::ParserError
  @body = nil
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/lorkhan/response.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/lorkhan/response.rb', line 8

def headers
  @headers
end

Instance Method Details

#apns_idObject

Get the APNS id for the notification



35
36
37
# File 'lib/lorkhan/response.rb', line 35

def apns_id
  headers['apns-id']
end

#ok?Boolean

Convenience method to check if the status is 200



21
22
23
# File 'lib/lorkhan/response.rb', line 21

def ok?
  status == 200
end

#statusObject

Get the HTTP status



28
29
30
# File 'lib/lorkhan/response.rb', line 28

def status
  headers[':status'].to_i
end