Class: KakaoPush::Response
- Inherits:
-
Object
- Object
- KakaoPush::Response
- Defined in:
- lib/kakao_push/response.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #data ⇒ Object
- #error_code ⇒ Object
- #error_message ⇒ Object
- #fail? ⇒ Boolean
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 |
# File 'lib/kakao_push/response.rb', line 8 def initialize(faraday_response) self.raw_body = faraday_response.body self.status = faraday_response.status self.body = MultiJson.load(raw_body) if raw_body && !raw_body.empty? end |
Instance Attribute Details
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/kakao_push/response.rb', line 6 def status @status end |
Instance Method Details
#data ⇒ Object
22 23 24 |
# File 'lib/kakao_push/response.rb', line 22 def data success? ? body : nil end |
#error_code ⇒ Object
26 27 28 29 |
# File 'lib/kakao_push/response.rb', line 26 def error_code return if success? body['code'] if body.is_a?(Hash) && body.has_key?('code') end |
#error_message ⇒ Object
31 32 33 34 |
# File 'lib/kakao_push/response.rb', line 31 def return if success? body['msg'] if body.is_a?(Hash) && body.has_key?('msg') end |
#fail? ⇒ Boolean
18 19 20 |
# File 'lib/kakao_push/response.rb', line 18 def fail? !success? end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/kakao_push/response.rb', line 14 def success? status == 200 end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kakao_push/response.rb', line 36 def to_s <<-EOS KakaoPush::Response status : #{status} success? : #{success?} fail? : #{fail?} data : #{data} error_code : #{error_code} error_message : #{} EOS end |