Class: Lakala::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/lakala/response.rb', line 9

def initialize(res)
  @net_http_response = res
  @body = JSON.parse(res.body&.dup&.force_encoding('UTF-8'))
  @code = res.code
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/lakala/response.rb', line 5

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/lakala/response.rb', line 5

def code
  @code
end

#net_http_responseObject (readonly)

Returns the value of attribute net_http_response.



5
6
7
# File 'lib/lakala/response.rb', line 5

def net_http_response
  @net_http_response
end

Instance Method Details

#error_codeObject



23
24
25
# File 'lib/lakala/response.rb', line 23

def error_code
  @body['code'] if failed?
end

#error_msgObject



27
28
29
# File 'lib/lakala/response.rb', line 27

def error_msg
  @body['msg'] if failed?
end

#failed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/lakala/response.rb', line 19

def failed?
  @net_http_response.code != '200'
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/lakala/response.rb', line 15

def success?
  !failed?
end