Class: KakaoPush::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/kakao_push/response.rb', line 6

def status
  @status
end

Instance Method Details

#dataObject



22
23
24
# File 'lib/kakao_push/response.rb', line 22

def data
  success? ? body : nil
end

#error_codeObject



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_messageObject



31
32
33
34
# File 'lib/kakao_push/response.rb', line 31

def error_message
  return if success?
  body['msg'] if body.is_a?(Hash) && body.has_key?('msg')
end

#fail?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/kakao_push/response.rb', line 18

def fail?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/kakao_push/response.rb', line 14

def success?
  status == 200
end

#to_sObject



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 : #{error_message}

  EOS
end