MCM Phone Number Generator
MCM Phone Number Generator is a Ruby gem that provides seamless integration with My Country Mobile's Phone Number Generator Tool. With this gem, developers can programmatically generate phone numbers for various countries and types (e.g., mobile, landline, VoIP) using the My Country Mobile API.
Features
- Generate Phone Numbers: Quickly generate phone numbers for different countries and types.
-
Customizable Parameters: Pass parameters like
country
andtype
to tailor your phone numbers. - Easy Integration: Simple Ruby interface with minimal setup.
- Error Handling: Built-in error handling for smooth API interactions.
Installation
Add the gem to your Gemfile:
gem 'mcm_phone_number_generator'
Then run:
bundle install
Or install it manually:
gem install mcm_phone_number_generator
Usage
Step 1: Require the Gem
Load the gem into your Ruby script:
require 'mcm_phone_number_generator'
Step 2: Initialize the Client
Create an instance of the client. Specify the API URL for My Country Mobile:
client = MCMPhoneNumberGenerator::Client.new("https://www.mycountrymobile.com/api/v1")
Step 3: Generate a Phone Number
Call the generate_phone_number
method with the required parameters:
params = { country: "US", type: "mobile" }
result = client.generate_phone_number(params)
puts "Generated Phone Number: #{result['number']}"
Example Output
{
"number": "+1-555-123-4567",
"country": "US",
"type": "mobile"
}
API Parameters
The following parameters can be passed to the generate_phone_number
method:
Parameter | Type | Required | Description |
---|---|---|---|
country |
String |
Yes | The country code (e.g., "US"). |
type |
String |
Yes | The type of number (e.g., "mobile"). |
Error Handling
The gem includes robust error handling. Here's an example of how to handle errors gracefully:
begin
result = client.generate_phone_number(params)
puts "Generated Phone Number: #{result['number']}"
rescue MCMPhoneNumberGenerator::APIError => e
puts "An error occurred: #{e.message}"
end
Common error scenarios:
- Network Errors: Raised if there are issues connecting to the API.
- Invalid Parameters: Raised if required parameters are missing or invalid.
-
API Errors: Raised if the API returns a non-successful response (e.g.,
400 Bad Request
).
Development
To contribute or modify this gem:
- Clone the repository:
git clone https://github.com/your-username/mcm_phone_number_generator.git cd mcm_phone_number_generator
- Install dependencies:
bundle install
- Run tests:
bundle exec rspec
Example Application
Here’s a quick example of how you can use this gem in a real-world application:
require 'mcm_phone_number_generator'
client = MCMPhoneNumberGenerator::Client.new("https://www.mycountrymobile.com/api/v1")
params = { country: "IN", type: "landline" }
begin
result = client.generate_phone_number(params)
puts "Generated Phone Number: #{result['number']}"
rescue MCMPhoneNumberGenerator::APIError => e
puts "Error: #{e.message}"
end
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you'd like to contribute to this gem.
To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add new feature'
- Push to the branch:
git push origin my-new-feature
- Open a pull request on GitHub.
License
This gem is open-source and available under the MIT License.
Additional Resources
Contact
For support or questions, reach out at:
- Email: info@mycountrymobile.com
- Website: My Country Mobile
---
### **Key Features of This README**
1. **Comprehensive Documentation**:
- Includes installation instructions, usage examples, API parameters, and error handling.
2. **Development Instructions**:
- Clearly explains how contributors can set up and test the gem.
3. **Real Examples**:
- Provides sample code and example outputs.
4. **Additional Resources**:
- Links to related tools and documentation.
5. **Professional Layout**:
- Easy to read with clear sections and formatting.
---