Class: Plivo::Base::Response

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

Overview

A class to provide a blanket response based on what is being received from Plivo servers.

This will be used only during POST and DELETE requests.

Instance Method Summary collapse

Constructor Details

#initialize(response_hash, id_symbol = nil) ⇒ Response

Instantiating a new instance requires a response_hash The id_symbol should contain a Symbol that represents the identifier of the resource for which this response is being generated for.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/plivo/base/response.rb', line 15

def initialize(response_hash, id_symbol = nil)
  return unless response_hash

  response_hash.each do |k, v|
    instance_variable_set("@#{k}", v)
    self.class.send(:attr_reader, k)
  end
  return unless id_symbol && response_hash.key?(id_symbol)

  self.class.send(:attr_reader, :id)
  @id = response_hash[id_symbol]
end

Instance Method Details

#to_sObject



28
29
30
31
32
33
34
# File 'lib/plivo/base/response.rb', line 28

def to_s
  h = self.instance_variables.map do |attribute|
    key = attribute.to_s.gsub('@','')
    [key, self.instance_variable_get(attribute)]
  end.to_h
  h.to_s
end