This gem is a phone number validator using numverify.com API.
In order to use this gem, first you need to create an account (there are free accounts) to get an access token, which will be required everytime you request a validation for a new phone number.
#DONE: Request phone number validations
#TODO: use API ability to specify country_code parameter on request
Add this line to your application's Gemfile:
gem 'phone_validation', :git => 'https://github.com/dantgn/phone_validation.git'And then execute:
$ bundle
Initialize PhoneValidation Client with your access token from numverify.com and the phone number you want to validate.
phone = PhoneValidation::Client.new(token: 'token', phone_number: '+34977123123')ask the client for
phone.valid? # => true
phone.number # => '34977123123'
phone.local_format # => '977123123'
phone.international_format # => '+34977123123'
phone.country_prefix # => '+34'
phone.country_code # => 'ES'
phone.country_name # => 'Spain'
phone.location # => 'Tarragona'
phone.carrier # => ''
phone.line_type # => 'landline'Errors from 3rd party API (numverify.com)
phone = PhoneValidation::Client.new(token: 'wrong_token', phone_number: '+34977123123')
phone.valid?
# => PhoneValidation::Errors::ApiInternalError: You have not supplied a valid API Access Key. [Technical Support: support@apilayer.com]
# Original API response
{
"success":false,
"error":{
"code":101,
"type":"invalid_access_key",
"info":"You have not supplied a valid API Access Key. [Technical Support: support@apilayer.com]"
}
}Bug reports and pull requests are welcome on GitHub at https://github.com/dantgn/phone_validation.
The gem is available as open source under the terms of the MIT License.