Class: M2X::Client::Response

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

Overview

Response wrapper for M2X client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



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

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/m2x/response.rb', line 3

def response
  @response
end

Instance Method Details

#client_error?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/m2x/response.rb', line 29

def client_error?
  (400..499).include?(status)
end

#error?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/m2x/response.rb', line 37

def error?
  client_error? || server_error?
end

#headersObject



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

def headers
  @headers ||= @response.to_hash
end

#jsonObject



13
14
15
# File 'lib/m2x/response.rb', line 13

def json
  @json ||= ::JSON.parse(raw)
end

#rawObject



9
10
11
# File 'lib/m2x/response.rb', line 9

def raw
  @response.body
end

#server_error?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/m2x/response.rb', line 33

def server_error?
  (500..599).include?(status)
end

#statusObject



17
18
19
# File 'lib/m2x/response.rb', line 17

def status
  @status ||= @response.code.to_i
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/m2x/response.rb', line 25

def success?
  (200..299).include?(status)
end