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



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



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_sObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kakao_push/response.rb', line 36

def to_s
  "KakaoPush::Response\nstatus : \#{status}\nsuccess? : \#{success?}\nfail? : \#{fail?}\ndata : \#{data}\nerror_code : \#{error_code}\nerror_message : \#{error_message}\n\n  EOS\nend\n"