mcm_phone_number_generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +193 -0
- data/lib/mcm_phone_number_generator/version.rb +5 -0
- data/lib/mcm_phone_number_generator.rb +45 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6933711e10cc03f6a6882297c862b6e7c02910150ff6765ef830bc56c00722e
|
4
|
+
data.tar.gz: c9a82c80312f11c2c1156aace0a07aecf04de6079aad8fb893fcdf4a7861a69c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2124b06593282bbb8d779ea33e1e10cdfc354dbb7109be9f1b74b1a7472e9057cecbb4a791496f83382ce21a5a226817e2eaa665a4f68c8281c8f857d733c90
|
7
|
+
data.tar.gz: 2730ec1944f5744f2ed32c9410c2e486932324c2e6e8b23e400c954cac0f8dcd06ab734a40052b7b6701665422f9aeb972eedfe44a34a5aaf2cd3fb1d5d68f35
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
# MCM Phone Number Generator
|
2
|
+
|
3
|
+
**MCM Phone Number Generator** is a Ruby gem that provides seamless integration with My Country Mobile's [Phone Number Generator Tool](https://www.mycountrymobile.com/tools/phone-number-generator/). 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.
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- **Generate Phone Numbers:** Quickly generate phone numbers for different countries and types.
|
10
|
+
- **Customizable Parameters:** Pass parameters like `country` and `type` to tailor your phone numbers.
|
11
|
+
- **Easy Integration:** Simple Ruby interface with minimal setup.
|
12
|
+
- **Error Handling:** Built-in error handling for smooth API interactions.
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add the gem to your Gemfile:
|
19
|
+
```ruby
|
20
|
+
gem 'mcm_phone_number_generator'
|
21
|
+
```
|
22
|
+
|
23
|
+
Then run:
|
24
|
+
```bash
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
Or install it manually:
|
29
|
+
```bash
|
30
|
+
gem install mcm_phone_number_generator
|
31
|
+
```
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### Step 1: Require the Gem
|
38
|
+
Load the gem into your Ruby script:
|
39
|
+
```ruby
|
40
|
+
require 'mcm_phone_number_generator'
|
41
|
+
```
|
42
|
+
|
43
|
+
### Step 2: Initialize the Client
|
44
|
+
Create an instance of the client. Specify the API URL for My Country Mobile:
|
45
|
+
```ruby
|
46
|
+
client = MCMPhoneNumberGenerator::Client.new("https://www.mycountrymobile.com/api/v1")
|
47
|
+
```
|
48
|
+
|
49
|
+
### Step 3: Generate a Phone Number
|
50
|
+
Call the `generate_phone_number` method with the required parameters:
|
51
|
+
```ruby
|
52
|
+
params = { country: "US", type: "mobile" }
|
53
|
+
result = client.generate_phone_number(params)
|
54
|
+
puts "Generated Phone Number: #{result['number']}"
|
55
|
+
```
|
56
|
+
|
57
|
+
#### Example Output
|
58
|
+
```json
|
59
|
+
{
|
60
|
+
"number": "+1-555-123-4567",
|
61
|
+
"country": "US",
|
62
|
+
"type": "mobile"
|
63
|
+
}
|
64
|
+
```
|
65
|
+
|
66
|
+
---
|
67
|
+
|
68
|
+
## API Parameters
|
69
|
+
|
70
|
+
The following parameters can be passed to the `generate_phone_number` method:
|
71
|
+
|
72
|
+
| Parameter | Type | Required | Description |
|
73
|
+
|-----------|----------|----------|--------------------------------------|
|
74
|
+
| `country` | `String` | Yes | The country code (e.g., "US"). |
|
75
|
+
| `type` | `String` | Yes | The type of number (e.g., "mobile"). |
|
76
|
+
|
77
|
+
---
|
78
|
+
|
79
|
+
## Error Handling
|
80
|
+
|
81
|
+
The gem includes robust error handling. Here's an example of how to handle errors gracefully:
|
82
|
+
```ruby
|
83
|
+
begin
|
84
|
+
result = client.generate_phone_number(params)
|
85
|
+
puts "Generated Phone Number: #{result['number']}"
|
86
|
+
rescue MCMPhoneNumberGenerator::APIError => e
|
87
|
+
puts "An error occurred: #{e.message}"
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
Common error scenarios:
|
92
|
+
- **Network Errors:** Raised if there are issues connecting to the API.
|
93
|
+
- **Invalid Parameters:** Raised if required parameters are missing or invalid.
|
94
|
+
- **API Errors:** Raised if the API returns a non-successful response (e.g., `400 Bad Request`).
|
95
|
+
|
96
|
+
---
|
97
|
+
|
98
|
+
## Development
|
99
|
+
|
100
|
+
To contribute or modify this gem:
|
101
|
+
1. Clone the repository:
|
102
|
+
```bash
|
103
|
+
git clone https://github.com/your-username/mcm_phone_number_generator.git
|
104
|
+
cd mcm_phone_number_generator
|
105
|
+
```
|
106
|
+
2. Install dependencies:
|
107
|
+
```bash
|
108
|
+
bundle install
|
109
|
+
```
|
110
|
+
3. Run tests:
|
111
|
+
```bash
|
112
|
+
bundle exec rspec
|
113
|
+
```
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
## Example Application
|
118
|
+
|
119
|
+
Here’s a quick example of how you can use this gem in a real-world application:
|
120
|
+
```ruby
|
121
|
+
require 'mcm_phone_number_generator'
|
122
|
+
|
123
|
+
client = MCMPhoneNumberGenerator::Client.new("https://www.mycountrymobile.com/api/v1")
|
124
|
+
params = { country: "IN", type: "landline" }
|
125
|
+
|
126
|
+
begin
|
127
|
+
result = client.generate_phone_number(params)
|
128
|
+
puts "Generated Phone Number: #{result['number']}"
|
129
|
+
rescue MCMPhoneNumberGenerator::APIError => e
|
130
|
+
puts "Error: #{e.message}"
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
---
|
135
|
+
|
136
|
+
## Contributing
|
137
|
+
|
138
|
+
Contributions are welcome! Please open an issue or submit a pull request if you'd like to contribute to this gem.
|
139
|
+
|
140
|
+
To contribute:
|
141
|
+
1. Fork the repository.
|
142
|
+
2. Create a new branch for your feature or bugfix:
|
143
|
+
```bash
|
144
|
+
git checkout -b my-new-feature
|
145
|
+
```
|
146
|
+
3. Commit your changes:
|
147
|
+
```bash
|
148
|
+
git commit -am 'Add new feature'
|
149
|
+
```
|
150
|
+
4. Push to the branch:
|
151
|
+
```bash
|
152
|
+
git push origin my-new-feature
|
153
|
+
```
|
154
|
+
5. Open a pull request on GitHub.
|
155
|
+
|
156
|
+
---
|
157
|
+
|
158
|
+
## License
|
159
|
+
|
160
|
+
This gem is open-source and available under the [MIT License](https://opensource.org/licenses/MIT).
|
161
|
+
|
162
|
+
---
|
163
|
+
|
164
|
+
## Additional Resources
|
165
|
+
|
166
|
+
- [My Country Mobile Phone Number Generator Tool](https://www.mycountrymobile.com/tools/phone-number-generator/)
|
167
|
+
- [Ruby Gems Documentation](https://guides.rubygems.org/)
|
168
|
+
- [HTTParty Documentation](https://github.com/jnunemaker/httparty)
|
169
|
+
|
170
|
+
---
|
171
|
+
|
172
|
+
## Contact
|
173
|
+
|
174
|
+
For support or questions, reach out at:
|
175
|
+
- **Email:** info@mycountrymobile.com
|
176
|
+
- **Website:** [My Country Mobile](https://www.mycountrymobile.com)
|
177
|
+
```
|
178
|
+
|
179
|
+
---
|
180
|
+
|
181
|
+
### **Key Features of This README**
|
182
|
+
1. **Comprehensive Documentation**:
|
183
|
+
- Includes installation instructions, usage examples, API parameters, and error handling.
|
184
|
+
2. **Development Instructions**:
|
185
|
+
- Clearly explains how contributors can set up and test the gem.
|
186
|
+
3. **Real Examples**:
|
187
|
+
- Provides sample code and example outputs.
|
188
|
+
4. **Additional Resources**:
|
189
|
+
- Links to related tools and documentation.
|
190
|
+
5. **Professional Layout**:
|
191
|
+
- Easy to read with clear sections and formatting.
|
192
|
+
|
193
|
+
---
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module MCMPhoneNumberGenerator
|
4
|
+
class APIError < StandardError; end
|
5
|
+
|
6
|
+
class Client
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
def initialize(base_uri = 'https://www.mycountrymobile.com/api/v1')
|
10
|
+
self.class.base_uri(base_uri)
|
11
|
+
@headers = { 'Content-Type' => 'application/json' } # Removed Authorization header
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_phone_number(params = {})
|
15
|
+
# Validate required parameters
|
16
|
+
validate_params!(params)
|
17
|
+
|
18
|
+
# Log the request for debugging purposes (optional)
|
19
|
+
puts "Requesting phone number generation with params: #{params}"
|
20
|
+
|
21
|
+
# Make the POST request
|
22
|
+
response = self.class.post('/phone-number-generator', headers: @headers, body: params.to_json)
|
23
|
+
|
24
|
+
# Raise an error if the response is unsuccessful
|
25
|
+
raise APIError, "Error: #{response.code} - #{response.message}" unless response.success?
|
26
|
+
|
27
|
+
# Parse and return the JSON response
|
28
|
+
JSON.parse(response.body)
|
29
|
+
rescue HTTParty::Error => e
|
30
|
+
raise APIError, "Network error occurred: #{e.message}"
|
31
|
+
rescue JSON::ParserError => e
|
32
|
+
raise APIError, "Response parsing error: #{e.message}"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def validate_params!(params)
|
38
|
+
required_keys = [:country, :type]
|
39
|
+
missing_keys = required_keys.select { |key| !params.key?(key) }
|
40
|
+
unless missing_keys.empty?
|
41
|
+
raise ArgumentError, "Missing required parameters: #{missing_keys.join(', ')}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mcm_phone_number_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joanna
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: httparty
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.20.0
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.20.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.6'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rspec
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.12'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rubocop
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.30'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.30'
|
68
|
+
description: This gem allows developers to programmatically generate phone numbers
|
69
|
+
using My Country Mobile's API. It supports country-specific and type-specific phone
|
70
|
+
number generation with easy Ruby integration.
|
71
|
+
email:
|
72
|
+
- info@mycountrymobile.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- CHANGELOG.md
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- lib/mcm_phone_number_generator.rb
|
81
|
+
- lib/mcm_phone_number_generator/version.rb
|
82
|
+
homepage: https://www.mycountrymobile.com/tools/phone-number-generator/
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
allowed_push_host: https://rubygems.org
|
87
|
+
homepage_uri: https://www.mycountrymobile.com/tools/phone-number-generator/
|
88
|
+
source_code_uri: https://github.com/khanaariyan/mcm_phone_number_generator
|
89
|
+
changelog_uri: https://github.com/khanaariyan/mcm_phone_number_generator/blob/main/CHANGELOG.md
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.1.0
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.6.2
|
105
|
+
specification_version: 4
|
106
|
+
summary: A Ruby gem for interacting with My Country Mobile's Phone Number Generator
|
107
|
+
tool.
|
108
|
+
test_files: []
|