Class: Surveygizmo::Response

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

Defined Under Namespace

Classes: ParseSurveygizmoResponse, RaiseErrorOnFailedRequest

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response



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

def initialize(response)
  @response = mashify(response)
  @data     = @response.data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object



18
19
20
# File 'lib/surveygizmo/response.rb', line 18

def method_missing(name, *arguments, &block)
  @data.send(name, *arguments, &block)
end

Class Attribute Details

.mash_classObject

Returns the value of attribute mash_class



8
9
10
# File 'lib/surveygizmo/response.rb', line 8

def mash_class
  @mash_class
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data



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

def data
  @data
end

#responseObject (readonly)

Returns the value of attribute response



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

def response
  @response
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  (self.data == other.data) && (self.result == other.result)
end

#mashify(body) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/surveygizmo/response.rb', line 37

def mashify(body)
  case body
  when Hash
    self.class.mash_class.new(body)
  when Array
    body.map { |item| mashify(item) }
  else
    body
  end
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  @response.result_ok
end