namabar 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/.rspec +3 -0
- data/.rubocop.yml +335 -0
- data/CHANGELOG.md +28 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +136 -0
- data/LICENSE.txt +21 -0
- data/README.md +183 -0
- data/Rakefile +12 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/namabar/client.rb +80 -0
- data/lib/namabar/configuration.rb +58 -0
- data/lib/namabar/endpoints.rb +175 -0
- data/lib/namabar/version.rb +17 -0
- data/lib/namabar.rb +82 -0
- data/namabar.gemspec +38 -0
- data/sig/client.rbs +65 -0
- data/sig/configuration.rbs +50 -0
- data/sig/endpoints.rbs +44 -0
- data/sig/namabar.rbs +68 -0
- data/sig/version.rbs +15 -0
- metadata +89 -0
data/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Namabar Ruby SDK
|
|
2
|
+
|
|
3
|
+
A lightweight Ruby SDK for interacting with the Namabar OTP & Messaging API. Provides simple, well-documented methods for each API endpoint with seamless HTTParty integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Easy Setup**: Configure API credentials once, use everywhere
|
|
8
|
+
- **Complete API Coverage**: All OTP verification and messaging endpoints
|
|
9
|
+
- **Type Safety**: Full RBS type definitions included
|
|
10
|
+
- **Zero Heavy Dependencies**: Just HTTParty and that's it!
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add to your `Gemfile`:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'namabar'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then run:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install directly:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install namabar
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Configure your API credentials before using the client:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
Namabar.configure do |config|
|
|
38
|
+
config.api_key = ENV.fetch('NAMABAR__API_KEY')
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Create a client and start making API calls:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
client = Namabar.client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### OTP Verification
|
|
51
|
+
|
|
52
|
+
**Create and send a verification code:**
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
response = client.create_verification_code(
|
|
56
|
+
to: '+964751234567',
|
|
57
|
+
service_id: 'your-service-id',
|
|
58
|
+
locale: 'en', # optional
|
|
59
|
+
external_id: 'user-123', # optional
|
|
60
|
+
template_data: { name: 'John' } # optional
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
if response.success?
|
|
64
|
+
verification_id = response.parsed_response['id']
|
|
65
|
+
puts "Verification code sent! ID: #{verification_id}"
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Verify the code:**
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
response = client.verify_verification_code(
|
|
73
|
+
id: verification_id,
|
|
74
|
+
code: '123456'
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if response.success?
|
|
78
|
+
puts "Code verified successfully!"
|
|
79
|
+
else
|
|
80
|
+
puts "Verification failed: #{response.parsed_response['message']}"
|
|
81
|
+
end
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Get verification code details:**
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
response = client.get_verification_code_by_id(id: verification_id)
|
|
88
|
+
puts response.parsed_response
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Messaging
|
|
92
|
+
|
|
93
|
+
**Send a message:**
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
response = client.send_message(
|
|
97
|
+
type: 'Text',
|
|
98
|
+
to: '+964751234567',
|
|
99
|
+
service_id: 'your-service-id',
|
|
100
|
+
text: 'Hello from Namabar!', # optional (for custom text)
|
|
101
|
+
template: 'welcome_template', # optional (for templates)
|
|
102
|
+
external_id: 'msg-456' # optional
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if response.success?
|
|
106
|
+
message_id = response.parsed_response['id']
|
|
107
|
+
puts "Message sent! ID: #{message_id}"
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Get message details:**
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
response = client.get_message(id: message_id)
|
|
115
|
+
puts response.parsed_response
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Check message status:**
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
response = client.get_message_status(id: message_id)
|
|
122
|
+
status = response.parsed_response['status']
|
|
123
|
+
puts "Message status: #{status}"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Response Handling
|
|
127
|
+
|
|
128
|
+
All methods return `HTTParty::Response` objects:
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
response = client.create_verification_code(...)
|
|
132
|
+
|
|
133
|
+
# Check success
|
|
134
|
+
if response.success?
|
|
135
|
+
data = response.parsed_response
|
|
136
|
+
puts "Success: #{data}"
|
|
137
|
+
else
|
|
138
|
+
puts "Error #{response.code}: #{response.parsed_response['message']}"
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Access raw response
|
|
142
|
+
puts response.body
|
|
143
|
+
puts response.headers
|
|
144
|
+
puts response.code
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Error Handling
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
begin
|
|
151
|
+
response = client.create_verification_code(...)
|
|
152
|
+
rescue Namabar::Error => e
|
|
153
|
+
puts "Namabar SDK error: #{e.message}"
|
|
154
|
+
rescue => e
|
|
155
|
+
puts "General error: #{e.message}"
|
|
156
|
+
end
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
The SDK provides these methods corresponding to Namabar API endpoints:
|
|
162
|
+
|
|
163
|
+
**OTP Verification:**
|
|
164
|
+
|
|
165
|
+
- `create_verification_code(to:, service_id:, **options)` - Create and send OTP
|
|
166
|
+
- `verify_verification_code(id:, code:)` - Verify OTP code
|
|
167
|
+
- `get_verification_code_by_id(id:)` - Get verification details
|
|
168
|
+
|
|
169
|
+
**Messaging:**
|
|
170
|
+
|
|
171
|
+
- `send_message(type:, to:, service_id:, **options)` - Send message
|
|
172
|
+
- `get_message(id:)` - Get message details
|
|
173
|
+
- `get_message_status(id:)` - Get message status
|
|
174
|
+
|
|
175
|
+
All methods return `HTTParty::Response` objects with the API response.
|
|
176
|
+
|
|
177
|
+
## Development & Contributing
|
|
178
|
+
|
|
179
|
+
Please refer to the [Development](/helpers/README.md) file for more information.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
Released under the MIT License. See [LICENSE](LICENSE.txt) for details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'namabar'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require 'irb'
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'httparty'
|
|
4
|
+
require_relative 'configuration'
|
|
5
|
+
require_relative 'endpoints'
|
|
6
|
+
|
|
7
|
+
module Namabar
|
|
8
|
+
# HTTP client for interacting with the Namabar API
|
|
9
|
+
#
|
|
10
|
+
# This class provides the core HTTP functionality for making requests to the Namabar API.
|
|
11
|
+
# It uses HTTParty for HTTP operations and includes all endpoint methods from the Endpoints module.
|
|
12
|
+
#
|
|
13
|
+
# The client automatically handles:
|
|
14
|
+
# - Base URI configuration
|
|
15
|
+
# - Authentication via API key headers
|
|
16
|
+
# - Content-Type and Accept headers
|
|
17
|
+
# - JSON request/response handling
|
|
18
|
+
#
|
|
19
|
+
# @example Basic usage
|
|
20
|
+
# # Configure globally first
|
|
21
|
+
# Namabar.configure do |config|
|
|
22
|
+
# config.api_key = 'your-api-key'
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# # Create and use client
|
|
26
|
+
# client = Namabar::Client.new
|
|
27
|
+
# response = client.send_message(
|
|
28
|
+
# type: 'sms',
|
|
29
|
+
# to: '+1234567890',
|
|
30
|
+
# text: 'Hello from Namabar!',
|
|
31
|
+
# service_id: 'sms-service'
|
|
32
|
+
# )
|
|
33
|
+
# puts response.code # => 200
|
|
34
|
+
# puts response.body # => parsed JSON response
|
|
35
|
+
#
|
|
36
|
+
# @see Endpoints
|
|
37
|
+
# @see Configuration
|
|
38
|
+
class Client
|
|
39
|
+
include HTTParty
|
|
40
|
+
include Endpoints
|
|
41
|
+
|
|
42
|
+
base_uri 'https://api.namabar.krd'
|
|
43
|
+
|
|
44
|
+
# Initialize a new Namabar API client
|
|
45
|
+
#
|
|
46
|
+
# Creates a new client instance using the global Namabar configuration.
|
|
47
|
+
# The client will be configured with the API key and default headers
|
|
48
|
+
# required for authentication and proper JSON communication.
|
|
49
|
+
#
|
|
50
|
+
# @raise [StandardError] if Namabar.configuration is nil or api_key is not set
|
|
51
|
+
#
|
|
52
|
+
# @example Create a client
|
|
53
|
+
# client = Namabar::Client.new
|
|
54
|
+
#
|
|
55
|
+
# @see Namabar.configure
|
|
56
|
+
def initialize
|
|
57
|
+
@config = Namabar.configuration
|
|
58
|
+
self.class.headers(
|
|
59
|
+
'Content-Type' => 'application/json',
|
|
60
|
+
'Accept' => 'application/json',
|
|
61
|
+
'X-API-Key' => @config.api_key
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Get default HTTP options for requests
|
|
66
|
+
#
|
|
67
|
+
# Returns a hash containing the default options that should be included
|
|
68
|
+
# with every HTTP request, including headers for authentication and content type.
|
|
69
|
+
#
|
|
70
|
+
# @return [Hash] hash containing default headers and options
|
|
71
|
+
#
|
|
72
|
+
# @example Using default options
|
|
73
|
+
# opts = client.default_options
|
|
74
|
+
# opts = opts.merge(query: { limit: 10 })
|
|
75
|
+
# response = HTTParty.get('/endpoint', opts)
|
|
76
|
+
def default_options
|
|
77
|
+
{ headers: self.class.headers }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Namabar
|
|
4
|
+
# Configuration class for storing Namabar API credentials and settings
|
|
5
|
+
#
|
|
6
|
+
# This class holds the configuration options required to authenticate
|
|
7
|
+
# and interact with the Namabar API. It's typically configured once
|
|
8
|
+
# globally and then used by all Client instances.
|
|
9
|
+
#
|
|
10
|
+
# @example Configure with API credentials
|
|
11
|
+
# config = Namabar::Configuration.new
|
|
12
|
+
# config.api_key = ENV.fetch('NAMABAR__API_KEY', nil)
|
|
13
|
+
#
|
|
14
|
+
# @example Configure using the global configuration
|
|
15
|
+
# Namabar.configure do |config|
|
|
16
|
+
# config.api_key = 'your-api-key'
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# @see Namabar.configure
|
|
20
|
+
class Configuration
|
|
21
|
+
# @return [String, nil] the API key for authenticating with the Namabar API
|
|
22
|
+
# @example Set API key
|
|
23
|
+
# config.api_key = '1234567890abcdef'
|
|
24
|
+
attr_accessor :api_key
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
# @return [Configuration, nil] the global configuration instance
|
|
29
|
+
attr_accessor :configuration
|
|
30
|
+
|
|
31
|
+
# Configure the Namabar gem with API credentials and settings
|
|
32
|
+
#
|
|
33
|
+
# This method provides a convenient way to set up the global configuration
|
|
34
|
+
# that will be used by all Client instances. The configuration object is
|
|
35
|
+
# yielded to the provided block for modification.
|
|
36
|
+
#
|
|
37
|
+
# @yield [config] Yields the configuration object for modification
|
|
38
|
+
# @yieldparam config [Configuration] the configuration instance to modify
|
|
39
|
+
# @return [Configuration] the configured Configuration instance
|
|
40
|
+
#
|
|
41
|
+
# @example Basic configuration
|
|
42
|
+
# Namabar.configure do |config|
|
|
43
|
+
# config.api_key = ENV.fetch('NAMABAR__API_KEY', nil)
|
|
44
|
+
# end
|
|
45
|
+
#
|
|
46
|
+
# @example Configuration with validation
|
|
47
|
+
# Namabar.configure do |config|
|
|
48
|
+
# config.api_key = ENV.fetch('NAMABAR_API_KEY') { raise 'API key required' }
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# @see Configuration
|
|
52
|
+
def configure
|
|
53
|
+
self.configuration ||= Configuration.new
|
|
54
|
+
yield(configuration)
|
|
55
|
+
configuration
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Namabar
|
|
4
|
+
# One to one mapping of API endpoint methods from OpenAPI specification
|
|
5
|
+
#
|
|
6
|
+
# This module contains methods that correspond to API endpoints defined
|
|
7
|
+
# in the OpenAPI spec. Each method provides a convenient Ruby interface to the HTTP endpoints.
|
|
8
|
+
#
|
|
9
|
+
# All methods return HTTParty::Response objects which can be used to
|
|
10
|
+
# access response data, status codes, headers, etc.
|
|
11
|
+
#
|
|
12
|
+
# @example Basic usage
|
|
13
|
+
# client = Namabar::Client.new
|
|
14
|
+
# response = client.some_endpoint(param: 'value')
|
|
15
|
+
# puts response.code
|
|
16
|
+
# puts response.body
|
|
17
|
+
module Endpoints
|
|
18
|
+
# Create Verification Code
|
|
19
|
+
#
|
|
20
|
+
# Generates and sends a new verification code to the specified recipient using the configured verify service.
|
|
21
|
+
#
|
|
22
|
+
# @param to [string] (required)
|
|
23
|
+
# @param locale [String] (optional)
|
|
24
|
+
# @param external_id [string] (optional)
|
|
25
|
+
# @param code [string] (optional)
|
|
26
|
+
# @param service_id [String] (required)
|
|
27
|
+
# @param template_data [object] (optional)
|
|
28
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
29
|
+
#
|
|
30
|
+
# @example
|
|
31
|
+
# response = create_verification_code(to: 'value', service_id: 'value')
|
|
32
|
+
# puts response.code
|
|
33
|
+
def create_verification_code(to:, service_id:, locale: nil, external_id: nil, code: nil, template_data: nil)
|
|
34
|
+
url = '/verification-codes'
|
|
35
|
+
opts = default_options
|
|
36
|
+
|
|
37
|
+
body_data = {
|
|
38
|
+
'to' => to,
|
|
39
|
+
'locale' => locale,
|
|
40
|
+
'externalId' => external_id,
|
|
41
|
+
'code' => code,
|
|
42
|
+
'serviceId' => service_id,
|
|
43
|
+
'templateData' => template_data
|
|
44
|
+
}.compact
|
|
45
|
+
|
|
46
|
+
unless body_data.empty?
|
|
47
|
+
opts = opts.merge(body: body_data.to_json)
|
|
48
|
+
opts[:headers] ||= {}
|
|
49
|
+
opts[:headers]['Content-Type'] = 'application/json'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
self.class.post(url, opts)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Verify OTP Code
|
|
56
|
+
#
|
|
57
|
+
# Verifies a previously sent verification code. Returns the verification status and any associated data.
|
|
58
|
+
#
|
|
59
|
+
# @param id [string] The id of the verification code to verify. (required)
|
|
60
|
+
# @param code [string] (required)
|
|
61
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# response = verify_verification_code(id: 'value', code: 'value')
|
|
65
|
+
# puts response.code
|
|
66
|
+
def verify_verification_code(id:, code:)
|
|
67
|
+
url = '/verification-codes/{id}/verify'
|
|
68
|
+
url = url.gsub('{id}', id.to_s)
|
|
69
|
+
opts = default_options
|
|
70
|
+
|
|
71
|
+
body_data = {
|
|
72
|
+
'code' => code
|
|
73
|
+
}.compact
|
|
74
|
+
|
|
75
|
+
unless body_data.empty?
|
|
76
|
+
opts = opts.merge(body: body_data.to_json)
|
|
77
|
+
opts[:headers] ||= {}
|
|
78
|
+
opts[:headers]['Content-Type'] = 'application/json'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
self.class.post(url, opts)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Get Verification Code
|
|
85
|
+
#
|
|
86
|
+
# Retrieves details about a specific verification code.
|
|
87
|
+
#
|
|
88
|
+
# @param id [string] The ID of the verification code to retrieve (required)
|
|
89
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
90
|
+
#
|
|
91
|
+
# @example
|
|
92
|
+
# response = get_verification_code_by_id(id: 'value')
|
|
93
|
+
# puts response.code
|
|
94
|
+
def get_verification_code_by_id(id:)
|
|
95
|
+
url = '/verification-codes/{id}'
|
|
96
|
+
url = url.gsub('{id}', id.to_s)
|
|
97
|
+
opts = default_options
|
|
98
|
+
|
|
99
|
+
self.class.get(url, opts)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Send New Message
|
|
103
|
+
#
|
|
104
|
+
# Creates and sends a new message through the specified messaging service. Requires the CreateMessage permission.
|
|
105
|
+
#
|
|
106
|
+
# @param type [String] (required)
|
|
107
|
+
# @param to [string] (required)
|
|
108
|
+
# @param external_id [string] (optional)
|
|
109
|
+
# @param service_id [String] (required)
|
|
110
|
+
# @param text [string] (optional)
|
|
111
|
+
# @param template [String] (optional)
|
|
112
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
113
|
+
#
|
|
114
|
+
# @example
|
|
115
|
+
# response = send_message(type: 'value', to: 'value', service_id: 'value')
|
|
116
|
+
# puts response.code
|
|
117
|
+
def send_message(type:, to:, service_id:, external_id: nil, text: nil, template: nil)
|
|
118
|
+
url = '/messages'
|
|
119
|
+
opts = default_options
|
|
120
|
+
|
|
121
|
+
body_data = {
|
|
122
|
+
'type' => type,
|
|
123
|
+
'to' => to,
|
|
124
|
+
'externalId' => external_id,
|
|
125
|
+
'serviceId' => service_id,
|
|
126
|
+
'text' => text,
|
|
127
|
+
'template' => template
|
|
128
|
+
}.compact
|
|
129
|
+
|
|
130
|
+
unless body_data.empty?
|
|
131
|
+
opts = opts.merge(body: body_data.to_json)
|
|
132
|
+
opts[:headers] ||= {}
|
|
133
|
+
opts[:headers]['Content-Type'] = 'application/json'
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
self.class.post(url, opts)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Get Message Details
|
|
140
|
+
#
|
|
141
|
+
# Retrieves detailed information about a specific message including its status, cost, and delivery information.
|
|
142
|
+
#
|
|
143
|
+
# @param id [string] The ID of the message to get. (required)
|
|
144
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
145
|
+
#
|
|
146
|
+
# @example
|
|
147
|
+
# response = get_message(id: 'value')
|
|
148
|
+
# puts response.code
|
|
149
|
+
def get_message(id:)
|
|
150
|
+
url = '/messages/{id}'
|
|
151
|
+
url = url.gsub('{id}', id.to_s)
|
|
152
|
+
opts = default_options
|
|
153
|
+
|
|
154
|
+
self.class.get(url, opts)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Get Message Status
|
|
158
|
+
#
|
|
159
|
+
# Retrieves the status of a specific message, can be used for polling message delivery status.
|
|
160
|
+
#
|
|
161
|
+
# @param id [string] The ID of the message to get. (required)
|
|
162
|
+
# @return [HTTParty::Response] the HTTP response object
|
|
163
|
+
#
|
|
164
|
+
# @example
|
|
165
|
+
# response = get_message_status(id: 'value')
|
|
166
|
+
# puts response.code
|
|
167
|
+
def get_message_status(id:)
|
|
168
|
+
url = '/messages/{id}/status'
|
|
169
|
+
url = url.gsub('{id}', id.to_s)
|
|
170
|
+
opts = default_options
|
|
171
|
+
|
|
172
|
+
self.class.get(url, opts)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Namabar
|
|
4
|
+
# The current version of the Namabar gem
|
|
5
|
+
#
|
|
6
|
+
# This constant follows semantic versioning (SemVer) conventions:
|
|
7
|
+
# - MAJOR: Incompatible API changes
|
|
8
|
+
# - MINOR: Backwards-compatible functionality additions
|
|
9
|
+
# - PATCH: Backwards-compatible bug fixes
|
|
10
|
+
#
|
|
11
|
+
# @return [String] the current version string
|
|
12
|
+
# @example Check the version
|
|
13
|
+
# puts Namabar::VERSION # => "0.1.0"
|
|
14
|
+
#
|
|
15
|
+
# @see https://semver.org/ Semantic Versioning specification
|
|
16
|
+
VERSION = '0.1.0'
|
|
17
|
+
end
|
data/lib/namabar.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'namabar/version'
|
|
4
|
+
require 'namabar/configuration'
|
|
5
|
+
require 'namabar/client'
|
|
6
|
+
require 'namabar/endpoints'
|
|
7
|
+
|
|
8
|
+
# The main Namabar module providing convenient access to the Namabar API
|
|
9
|
+
#
|
|
10
|
+
# This module serves as the primary entry point for the Namabar gem, offering:
|
|
11
|
+
# - Global configuration management
|
|
12
|
+
# - Client creation and management
|
|
13
|
+
# - Error handling for the entire gem
|
|
14
|
+
#
|
|
15
|
+
# @example Basic usage
|
|
16
|
+
# Namabar.configure do |config|
|
|
17
|
+
# config.api_key = 'your-api-key'
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# client = Namabar.client
|
|
21
|
+
# response = client.send_message(...)
|
|
22
|
+
#
|
|
23
|
+
# @see Client
|
|
24
|
+
# @see Configuration
|
|
25
|
+
module Namabar
|
|
26
|
+
# Base error class for all Namabar-related errors
|
|
27
|
+
#
|
|
28
|
+
# All errors raised by the Namabar gem inherit from this class,
|
|
29
|
+
# making it easy to rescue all gem-related errors with a single rescue clause.
|
|
30
|
+
#
|
|
31
|
+
# @example Rescuing all Namabar errors
|
|
32
|
+
# begin
|
|
33
|
+
# client.send_message(...)
|
|
34
|
+
# rescue Namabar::Error => e
|
|
35
|
+
# puts "Namabar error: #{e.message}"
|
|
36
|
+
# end
|
|
37
|
+
class Error < StandardError; end
|
|
38
|
+
|
|
39
|
+
class << self
|
|
40
|
+
# @return [Configuration, nil] the current global configuration instance
|
|
41
|
+
attr_accessor :configuration
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Configure the Namabar gem globally
|
|
45
|
+
#
|
|
46
|
+
# This method allows you to set global configuration options that will be
|
|
47
|
+
# used by all Client instances unless overridden. The configuration is
|
|
48
|
+
# yielded to the provided block for modification.
|
|
49
|
+
#
|
|
50
|
+
# @yield [config] Yields the configuration object for modification
|
|
51
|
+
# @yieldparam config [Configuration] the configuration instance to modify
|
|
52
|
+
# @return [Configuration] the configured Configuration instance
|
|
53
|
+
#
|
|
54
|
+
# @example Configure API credentials
|
|
55
|
+
# Namabar.configure do |config|
|
|
56
|
+
# config.api_key = ENV['NAMABAR_API_KEY']
|
|
57
|
+
# end
|
|
58
|
+
#
|
|
59
|
+
# @see Configuration
|
|
60
|
+
def self.configure
|
|
61
|
+
self.configuration ||= Configuration.new
|
|
62
|
+
yield(configuration)
|
|
63
|
+
configuration
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Create a new Namabar API client
|
|
67
|
+
#
|
|
68
|
+
# Creates and returns a new Client instance using the global configuration.
|
|
69
|
+
# This is a convenience method equivalent to calling Client.new directly.
|
|
70
|
+
#
|
|
71
|
+
# @param args [Array] arguments to pass to the Client constructor (currently none accepted)
|
|
72
|
+
# @return [Client] a new configured client instance
|
|
73
|
+
#
|
|
74
|
+
# @example Create a client
|
|
75
|
+
# client = Namabar.client
|
|
76
|
+
# response = client.send_message(...)
|
|
77
|
+
#
|
|
78
|
+
# @see Client#initialize
|
|
79
|
+
def self.client(*args)
|
|
80
|
+
Client.new(*args)
|
|
81
|
+
end
|
|
82
|
+
end
|
data/namabar.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/namabar/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'namabar'
|
|
7
|
+
spec.version = Namabar::VERSION
|
|
8
|
+
spec.authors = ['Muhammad Nawzad']
|
|
9
|
+
spec.email = ['hama127n@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Ruby SDK for Namabar OTP verification and messaging API'
|
|
12
|
+
spec.description = 'A lightweight Ruby SDK providing HTTParty-based client with type definitions for the Namabar OTP verification and messaging platform.'
|
|
13
|
+
spec.homepage = 'https://github.com/muhammadnawzad/namabar-ruby-sdk'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
17
|
+
|
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/muhammadnawzad/namabar-ruby-sdk/blob/main/CHANGELOG.md'
|
|
20
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/namabar'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/muhammadnawzad/namabar-ruby-sdk/issues'
|
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
23
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
24
|
+
|
|
25
|
+
# Specify which files should be added to the gem when it is released
|
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
28
|
+
f.match(%r{\A(?:(?:test|spec|features|helpers)/|\.(?:git|github|DS_Store))})
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
spec.bindir = 'exe'
|
|
33
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
34
|
+
spec.require_paths = ['lib']
|
|
35
|
+
|
|
36
|
+
# Runtime dependencies
|
|
37
|
+
spec.add_dependency 'httparty', '~> 0.2', '>= 0.2.0'
|
|
38
|
+
end
|