class Plivo::Base::Response

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.

Public Class Methods

new(response_hash, id_symbol = nil) click to toggle source

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.

# 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

Public Instance Methods

to_s() click to toggle source
# 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