class Plivo::Resources::LookupResponse

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

Public Class Methods

new(client, options = nil) click to toggle source
# 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

Public Instance Methods

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