Class: RubyVibe::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-vibe/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/ruby-vibe/response.rb', line 6

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/ruby-vibe/response.rb', line 4

def response
  @response
end

Class Method Details

.parse(response) ⇒ Object



11
12
13
14
# File 'lib/ruby-vibe/response.rb', line 11

def parse(response)
  response = new(response)
  response.parse
end

Instance Method Details

#parseObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-vibe/response.rb', line 17

def parse
  success       = true
  error_message = nil
  hash          = JSON.parse(response.body)

  unless hash.dig('status').to_i == 0
    success = false 
    error_message =  hash.dig('status_message')
  end
 
  Struct.new(:success?, :se, :error_message).new(success, hash, error_message)
end