Class: Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/repro/api/response.rb', line 7

def initialize(res)
  @code = res.code
  @message = res.is_a?(Net::HTTPSuccess) ? nil : res.message
  @body = JSON.parse(res.body)
  @error = if @body['error'] && @body['error']['messages']
             if @body['error']['messages'].is_a?(Array)
               @body['error']['messages'].join('. ')
             else
               @body['error']['messages']
             end
           else
             @body['error']
           end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

Instance Method Details

#codeObject



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

def code
  @code.to_i
end