Class: Rubyflare::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, endpoint, response) ⇒ Response

Returns a new instance of Response.


5
6
7
8
9
10
11
12
13
14
# File 'lib/rubyflare/response.rb', line 5

def initialize(method_name, endpoint, response)
  @body = JSON.parse(response, symbolize_names: true)

  unless successful?
    message = "Unable to #{method_name.to_s.upcase} to endpoint: " \
              "#{endpoint}. Inspect Rubyflare::ConnectionError#response "\
              "for further details"
    raise Rubyflare::ConnectionError.new(message, self)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body


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

def body
  @body
end

Instance Method Details

#errorsObject


28
29
30
# File 'lib/rubyflare/response.rb', line 28

def errors
  body[:errors]
end

#messagesObject


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

def messages
  body[:messages]
end

#resultObject


16
17
18
# File 'lib/rubyflare/response.rb', line 16

def result
  body[:result].first
end

#resultsObject


20
21
22
# File 'lib/rubyflare/response.rb', line 20

def results
  body[:result]
end

#successful?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/rubyflare/response.rb', line 24

def successful?
  body[:success]
end