Class: Plivo::Resources::LookupResponse

Inherits:
LookupBaseResource show all
Defined in:
lib/plivo/resources/lookup.rb

Overview

Not subclassing from Base::Resource because it cannot set nested attributes. Named the class ‘LookupResponse’ because the name ‘Number’ is already taken.

Instance Method Summary collapse

Methods inherited from LookupBaseResource

#to_s

Constructor Details

#initialize(client, options = nil) ⇒ LookupResponse

Returns a new instance of LookupResponse.



34
35
36
37
38
# File 'lib/plivo/resources/lookup.rb', line 34

def initialize(client, options = nil)
  # there is no use for client here
  valid_param?(:options, options, Hash, false)
  parse_and_set(options[:resource_json]) if options.key?(:resource_json)
end

Instance Method Details

#parse_and_set(resp) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/plivo/resources/lookup.rb', line 40

def parse_and_set(resp)
  return unless resp
  valid_param?(:resp, resp, Hash, true)

  resp.each do |k, v|
    case k
    when "country"
      instance_variable_set("@#{k}", Country.new(v))
    when "format"
      instance_variable_set("@#{k}", NumberFormat.new(v))
    when "carrier"
      instance_variable_set("@#{k}", Carrier.new(v))
    else
      instance_variable_set("@#{k}", v)
    end
    self.class.send(:attr_reader, k)
  end
end