Class: VoiceBase::Response

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/voicebase/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

included

Constructor Details

#initialize(http_response, api_version = "1.1") ⇒ Response

Returns a new instance of Response.



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

def initialize(http_response, api_version = "1.1")
  @http_response = http_response
  if api_version.to_i < 2
    self.extend(VoiceBase::V1::Response)
  elsif api_version.to_i == 2
    self.extend(VoiceBase::V2::Response)
  elsif api_version.to_i == 3
    self.extend(VoiceBase::V3::Response)
  else
     raise UnknownApiVersionError
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

E.g.

response hash ‘statusMessage’ key, or



31
32
33
34
35
36
37
# File 'lib/voicebase/response.rb', line 31

def method_missing(method, *args, &block)
  if result = http_response.parsed_response[camelize_name(method)]
    result
  else
    super
  end
end

Instance Attribute Details

#http_responseObject

Returns the value of attribute http_response.



4
5
6
# File 'lib/voicebase/response.rb', line 4

def http_response
  @http_response
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


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

def ok?
  http_response.code && http_response.code >= 200 && http_response.code < 300
end