Class: Twilio::REST::Lookups::V1::PhoneNumberContext

Inherits:
InstanceContext show all
Defined in:
lib/twilio-ruby/rest/lookups/v1/phone_number.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, phone_number) ⇒ PhoneNumberContext

Initialize the PhoneNumberContext

Parameters:

  • version (Version)

    Version that contains the resource

  • phone_number (String)

    The phone number to lookup in [E.164](www.twilio.com/docs/glossary/what-e164) format, which consists of a + followed by the country code and subscriber number.



50
51
52
53
54
55
56
57
58
59
# File 'lib/twilio-ruby/rest/lookups/v1/phone_number.rb', line 50

def initialize(version, phone_number)
    super(version)
    

    # Path Solution
    @solution = { phone_number: phone_number,  }
    @uri = "/PhoneNumbers/#{@solution[:phone_number]}"

    
end

Instance Method Details

#fetch(country_code: :unset, type: :unset, add_ons: :unset, add_ons_data: :unset) ⇒ PhoneNumberInstance

Fetch the PhoneNumberInstance

Parameters:

  • country_code (String) (defaults to: :unset)

    The [ISO country code](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the phone number to fetch. This is used to specify the country when the phone number is provided in a national format.

  • type (Array[String]) (defaults to: :unset)

    The type of information to return. Can be: carrier or caller-name. The default is null. To retrieve both types of information, specify this parameter twice; once with carrier and once with caller-name as the value.

  • add_ons (Array[String]) (defaults to: :unset)

    The unique_name of an Add-on you would like to invoke. Can be the unique_name of an Add-on that is installed on your account. You can specify multiple instances of this parameter to invoke multiple Add-ons. For more information about Add-ons, see the [Add-ons documentation](www.twilio.com/docs/add-ons).

  • add_ons_data (Hash) (defaults to: :unset)

    Data specific to the add-on you would like to invoke. The content and format of this value depends on the add-on.

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/twilio-ruby/rest/lookups/v1/phone_number.rb', line 67

def fetch(
    country_code: :unset, 
    type: :unset, 
    add_ons: :unset, 
    add_ons_data: :unset
)

    params = Twilio::Values.of({
        'CountryCode' => country_code,
        'Type' => Twilio.serialize_list(type) { |e| e },
        'AddOns' => Twilio.serialize_list(add_ons) { |e| e },
    })
    params.merge!(Twilio.prefixed_collapsible_map(add_ons_data, 'AddOns'))
    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, params: params, headers: headers)
    PhoneNumberInstance.new(
        @version,
        payload,
        phone_number: @solution[:phone_number],
    )
end

#fetch_with_metadata(country_code: :unset, type: :unset, add_ons: :unset, add_ons_data: :unset) ⇒ PhoneNumberInstance

Fetch the PhoneNumberInstanceMetadata

Parameters:

  • country_code (String) (defaults to: :unset)

    The [ISO country code](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the phone number to fetch. This is used to specify the country when the phone number is provided in a national format.

  • type (Array[String]) (defaults to: :unset)

    The type of information to return. Can be: carrier or caller-name. The default is null. To retrieve both types of information, specify this parameter twice; once with carrier and once with caller-name as the value.

  • add_ons (Array[String]) (defaults to: :unset)

    The unique_name of an Add-on you would like to invoke. Can be the unique_name of an Add-on that is installed on your account. You can specify multiple instances of this parameter to invoke multiple Add-ons. For more information about Add-ons, see the [Add-ons documentation](www.twilio.com/docs/add-ons).

  • add_ons_data (Hash) (defaults to: :unset)

    Data specific to the add-on you would like to invoke. The content and format of this value depends on the add-on.

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/twilio-ruby/rest/lookups/v1/phone_number.rb', line 101

def (
  country_code: :unset, 
  type: :unset, 
  add_ons: :unset, 
  add_ons_data: :unset
)

    params = Twilio::Values.of({
        'CountryCode' => country_code,
        'Type' => Twilio.serialize_list(type) { |e| e },
        'AddOns' => Twilio.serialize_list(add_ons) { |e| e },
    })
    params.merge!(Twilio.prefixed_collapsible_map(add_ons_data, 'AddOns'))
    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, params: params, headers: headers)
    phone_number_instance = PhoneNumberInstance.new(
        @version,
        response.body,
        phone_number: @solution[:phone_number],
    )
    PhoneNumberInstanceMetadata.new(
        @version,
        phone_number_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



144
145
146
147
# File 'lib/twilio-ruby/rest/lookups/v1/phone_number.rb', line 144

def inspect
    context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
    "#<Twilio.Lookups.V1.PhoneNumberContext #{context}>"
end

#to_sObject

Provide a user friendly representation



137
138
139
140
# File 'lib/twilio-ruby/rest/lookups/v1/phone_number.rb', line 137

def to_s
    context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
    "#<Twilio.Lookups.V1.PhoneNumberContext #{context}>"
end