Class: MessageMediaLookups::LookupsController
- Inherits:
-
BaseController
- Object
- BaseController
- MessageMediaLookups::LookupsController
- Defined in:
- lib/message_media_lookups/controllers/lookups_controller.rb
Overview
LookupsController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_lookup_a_phone_number(phone_number, options = nil) ⇒ Object
Use the Lookups API to find information about a phone number.
- #instance ⇒ Object
Methods inherited from BaseController
#apply_authentication, #execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from MessageMediaLookups::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
8 9 10 |
# File 'lib/message_media_lookups/controllers/lookups_controller.rb', line 8 def instance @instance end |
Instance Method Details
#get_lookup_a_phone_number(phone_number, options = nil) ⇒ Object
Use the Lookups API to find information about a phone number.
A request to the lookups API has the following format:
/v1/lookups/phone/{phone_number}?options={carrier,type}
The {phone_number} parameter is a required field and should be set to
the phone number to be looked up.
The options query parameter can also be used to request additional
information about the phone number.
By default, a request will only return the country_code and
phone_number properties in the response.
To request details about the the carrier, include carrier as a value of
the options parameter.
To request details about the type, include type as a value of the
options parameter. To pass multiple values
to the options parameter, use a comma separated list, i.e. carrier,type.
A successful request to the lookups endpoint will return a response body
as follows:
{
"country_code": "AU",
"phone_number": "+61491570156",
"type": "mobile",
"carrier": {
"name": "Telstra"
}
}
Each property in the response body is defined as follows:
country_codeISO ALPHA 2 country code of the phone numberphone_numberE.164 formatted phone numbertypeThe type of number. This can be"mobile"or"landline"-
carrierHolds information about the specific carrier (if available)nameThe carrier's name as reported by the network looked up
53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/message_media_lookups/controllers/lookups_controller.rb', line 53 def get_lookup_a_phone_number(phone_number, = nil) begin @logger.info("get_lookup_a_phone_number called.") request_url = '/v1/lookups/phone/{phone_number}' request_url = APIHelper.append_url_with_template_parameters( request_url, 'phone_number' => phone_number ) # Prepare query url. @logger.info("Preparing query URL for get_lookup_a_phone_number.") _query_builder = Configuration.base_uri.dup _query_builder << '/v1/lookups/phone/{phone_number}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'phone_number' => phone_number ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'options' => }, array_serialization: Configuration.array_serialization ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. @logger.info("Preparing headers for get_lookup_a_phone_number.") _headers = { 'accept' => 'application/json', 'user-agent' => 'messagemedia-lookups-ruby-sdk-1.1.0' } # Prepare and execute HttpRequest. @logger.info('Preparing and executing HttpRequest for get_lookup_a_phone_number.') _request = @http_client.get( _query_url, headers: _headers ) apply_authentication(_request, request_url) # BasicAuth.apply(_request) _context = execute_request(_request, name: 'get_lookup_a_phone_number') # Validate response against endpoint and global error codes. @logger.info("Validating response for get_lookup_a_phone_number.") if _context.response.status_code == 404 raise APIException.new( 'Number was invalid', _context ) end validate_response(_context) # Return appropriate response type. @logger.info("Returning response for get_lookup_a_phone_number.") decoded = APIHelper.json_deserialize(_context.response.raw_body) LookupAPhoneNumberResponse.from_hash(decoded) rescue Exception => e @logger.error(e) raise e end end |
#instance ⇒ Object
11 12 13 |
# File 'lib/message_media_lookups/controllers/lookups_controller.rb', line 11 def instance self.class.instance end |