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.

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Method Summary collapse

Methods inherited from LookupBaseResource

#to_s

Methods included from Utils

GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?

Constructor Details

#initialize(client, options = nil) ⇒ LookupResponse

Returns a new instance of LookupResponse.



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

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



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

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