The MessageMedia Lookups API provides a number of endpoints for validating the phone numbers you’re sending to by checking their validity, type and carrier records.
This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.
- Open the command line interface or the terminal and navigate to the folder containing the source code.
- Run
gem build message_media_lookups.gemspecto build the gem. - Once built, the gem can be installed on the current work environment using
gem install message_media_lookups-1.0.0.gem
The following section explains how to use the MessageMediaLookups Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Close any existing projects in RubyMine™ by selecting File -> Close Project. Next, click on Create New Project to create a new project from scratch.
Next, provide TestApp as the project name, choose Rails Application as the project type, and click OK.
In the next dialog make sure that correct Ruby SDK is being used (minimum 2.0.0) and click OK.
This will create a new Rails Application project with an existing set of files and folder.
In order to use the MessageMediaLookups gem in the new project we must add a gem reference. Locate the Gemfile in the Project Explorer window under the TestApp project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: gem 'message_media_lookups', '~> 1.0.0'
Once the TestApp project is created, a folder named controllers will be visible in the Project Explorer under the following path: TestApp > app > controllers. Right click on this folder and select New -> Run Rails Generator....
Selecting the said option will popup a small window where the generator names are displayed. Here, select the controller template.
Next, a popup window will ask you for a Controller name and included Actions. For controller name provide Hello and include an action named Index and click OK.
A new controller class anmed HelloController will be created in a file named hello_controller.rb containing a method named Index. In this method, add code for initialization and a sample for its usage.
You can test the generated SDK and the server with automatically generated test cases as follows:
- From terminal/cmd navigate to the root directory of the SDK.
- Invoke:
bundle exec rake
In order to setup authentication and initialization of the API client, you need the following information.
| Parameter | Description |
|---|---|
| basic_auth_user_name | The username to use with basic authentication |
| basic_auth_password | The password to use with basic authentication |
API client can be initialized as following.
# Configuration parameters and credentials
basic_auth_user_name = 'basic_auth_user_name' # The username to use with basic authentication
basic_auth_password = 'basic_auth_password' # The password to use with basic authentication
client = MessageMediaLookups::MessageMediaLookupsClient.new(
basic_auth_user_name: basic_auth_user_name,
basic_auth_password: basic_auth_password
)The added initlization code can be debugged by putting a breakpoint in the Index method and running the project in debug mode by selecting Run -> Debug 'Development: TestApp'.
The singleton instance of the LookupsController class can be accessed from the API Client.
lookups_controller = client.lookupsUse 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 thecountry_codeandphone_numberproperties in the response. To request details about the the carrier, includecarrieras a value of the options parameter. To request details about the type, includetypeas 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
def get_lookup_a_phone_number(phone_number,
options = nil); end| Parameter | Tags | Description |
|---|---|---|
| phone_number | Required |
The phone number to be looked up |
| options | Optional |
TODO: Add a parameter description |
phone_number = '+61491570156'
options = 'carrier,type'
result = lookups_controller.get_lookup_a_phone_number(phone_number, options)| Error Code | Error Description |
|---|---|
| 404 | Number was invalid |

