comms_sdk 1.0.0 → 1.0.1
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 +4 -4
- data/.rspec +3 -3
- data/.standard.yml +3 -3
- data/LICENSE.txt +21 -21
- data/README.md +179 -12
- data/Rakefile +10 -10
- data/build_and_upload.sh +3 -0
- data/lib/comms_sdk/v1/README.md +166 -166
- data/lib/comms_sdk/v1/comms_sdk.rb +3 -3
- data/lib/comms_sdk/version.rb +5 -5
- data/lib/comms_sdk.rb +12 -12
- data/sig/comms_sdk.rbs +4 -4
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bd645fc9d43ee7901bbee4f47d065cecb985dab95eb167bacec0e9984df888d
|
|
4
|
+
data.tar.gz: 2ab419f94ce8b2f7966aeb0aa9ab568fefc4078378e9eb5bc8ef6c7119f3e87e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 599836f2e32cf109d8829689fe6b86459012378b0602d436cd69b6f8362e201d4900887b4caf589b20e8d85b6cbeac4ce6362696c1c55e6b976324c3bdb00e24
|
|
7
|
+
data.tar.gz: f6fb82669a9a5022574e207fec635a293ea948bacd368e0aa2fa7e6831cb0e75a08652e89897bf3fee189b5f33379b1c41e4165ad142fc9260de1fe9a435bbbc
|
data/.rspec
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
--format documentation
|
|
2
|
-
--color
|
|
3
|
-
--require spec_helper
|
|
1
|
+
--format documentation
|
|
2
|
+
--color
|
|
3
|
+
--require spec_helper
|
data/.standard.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# For available configuration options, see:
|
|
2
|
-
# https://github.com/standardrb/standard
|
|
3
|
-
ruby_version: 3.1
|
|
1
|
+
# For available configuration options, see:
|
|
2
|
+
# https://github.com/standardrb/standard
|
|
3
|
+
ruby_version: 3.1
|
data/LICENSE.txt
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,34 +1,201 @@
|
|
|
1
|
-
#
|
|
1
|
+
# comms_sdk Ruby SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Ruby implementation of the CommsSDK for sending SMS and managing communications, following the same patterns as the Python and Kotlin reference implementations.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Version:** 1.0.1
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Consistent API across all supported languages
|
|
12
|
+
- Authenticate with username and API key
|
|
13
|
+
- Send SMS to one or more recipients
|
|
14
|
+
- Optional sender ID and message priority
|
|
15
|
+
- Check account balance
|
|
16
|
+
- Comprehensive error handling
|
|
17
|
+
|
|
18
|
+
---
|
|
6
19
|
|
|
7
20
|
## Installation
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
Add this line to your application's Gemfile:
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
```ruby
|
|
25
|
+
gem 'comms_sdk', '~> 1.0.1'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
And then execute:
|
|
12
29
|
|
|
13
30
|
```bash
|
|
14
|
-
bundle
|
|
31
|
+
bundle install
|
|
15
32
|
```
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
Or install it yourself as:
|
|
18
35
|
|
|
19
36
|
```bash
|
|
20
|
-
gem install
|
|
37
|
+
gem install comms_sdk
|
|
21
38
|
```
|
|
22
39
|
|
|
40
|
+
---
|
|
41
|
+
|
|
23
42
|
## Usage
|
|
24
43
|
|
|
25
|
-
|
|
44
|
+
### Basic Authentication
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
require 'comms_sdk/v1'
|
|
48
|
+
|
|
49
|
+
# Authenticate with username and API key
|
|
50
|
+
sdk = CommsSdk::V1::CommsSDK.authenticate("your_username", "your_api_key")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Sending SMS
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Send SMS to a single number
|
|
57
|
+
success = sdk.send_sms("256712345678", "Hello from Ruby!")
|
|
58
|
+
|
|
59
|
+
# Send SMS to multiple numbers
|
|
60
|
+
success = sdk.send_sms(["256712345678", "256787654321"], "Hello to all!")
|
|
61
|
+
|
|
62
|
+
# Send SMS with custom sender ID and priority
|
|
63
|
+
success = sdk.send_sms(
|
|
64
|
+
"256712345678",
|
|
65
|
+
"Hello!",
|
|
66
|
+
sender_id: "MyApp",
|
|
67
|
+
priority: CommsSdk::V1::MessagePriority::HIGH
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Get full API response
|
|
71
|
+
response = sdk.query_send_sms(
|
|
72
|
+
["256712345678"],
|
|
73
|
+
"Hello!",
|
|
74
|
+
"MyApp",
|
|
75
|
+
CommsSdk::V1::MessagePriority::HIGHEST
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Checking Balance
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
# Get balance as a float
|
|
83
|
+
balance = sdk.get_balance
|
|
84
|
+
puts "Balance: #{balance}"
|
|
85
|
+
|
|
86
|
+
# Get full balance response
|
|
87
|
+
response = sdk.query_balance
|
|
88
|
+
puts "Status: #{response.status}"
|
|
89
|
+
puts "Balance: #{response.balance}"
|
|
90
|
+
puts "Currency: #{response.currency}"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Configuration
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
# Use sandbox environment
|
|
97
|
+
CommsSdk::V1::CommsSDK.use_sandbox
|
|
98
|
+
|
|
99
|
+
# Use live server (default)
|
|
100
|
+
CommsSdk::V1::CommsSDK.use_live_server
|
|
101
|
+
|
|
102
|
+
# Set custom sender ID
|
|
103
|
+
sdk.with_sender_id("MyCustomSender")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## API Reference
|
|
109
|
+
|
|
110
|
+
### CommsSdk::V1::CommsSDK
|
|
111
|
+
|
|
112
|
+
#### Class Methods
|
|
113
|
+
|
|
114
|
+
- `authenticate(user_name, api_key)`
|
|
115
|
+
Authenticate and return SDK instance.
|
|
116
|
+
- `use_sandbox`
|
|
117
|
+
Switch to sandbox environment.
|
|
118
|
+
- `use_live_server`
|
|
119
|
+
Switch to live environment.
|
|
120
|
+
|
|
121
|
+
#### Instance Methods
|
|
122
|
+
|
|
123
|
+
- `with_sender_id(sender_id)`
|
|
124
|
+
Set sender ID, returns self for chaining.
|
|
125
|
+
- `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)`
|
|
126
|
+
Send SMS, returns boolean.
|
|
127
|
+
- `query_send_sms(numbers, message, sender_id, priority)`
|
|
128
|
+
Send SMS, returns full ApiResponse.
|
|
129
|
+
- `get_balance`
|
|
130
|
+
Get account balance as float.
|
|
131
|
+
- `query_balance`
|
|
132
|
+
Get full balance response as ApiResponse.
|
|
133
|
+
- `set_authenticated`
|
|
134
|
+
Mark SDK as authenticated (internal use).
|
|
135
|
+
|
|
136
|
+
#### Attributes
|
|
137
|
+
|
|
138
|
+
- `api_key`
|
|
139
|
+
The API key used for authentication.
|
|
140
|
+
- `user_name`
|
|
141
|
+
The username used for authentication.
|
|
142
|
+
- `sender_id`
|
|
143
|
+
Current sender ID.
|
|
144
|
+
- `is_authenticated`
|
|
145
|
+
Authentication status.
|
|
146
|
+
|
|
147
|
+
### Models
|
|
148
|
+
|
|
149
|
+
#### MessagePriority
|
|
150
|
+
|
|
151
|
+
- `MessagePriority::HIGHEST` - Priority "0"
|
|
152
|
+
- `MessagePriority::HIGH` - Priority "1"
|
|
153
|
+
- `MessagePriority::MEDIUM` - Priority "2"
|
|
154
|
+
- `MessagePriority::LOW` - Priority "3"
|
|
155
|
+
- `MessagePriority::LOWEST` - Priority "4"
|
|
156
|
+
|
|
157
|
+
#### ApiResponse
|
|
158
|
+
|
|
159
|
+
- `status` - Response status ("OK" or "Failed")
|
|
160
|
+
- `message` - Response message
|
|
161
|
+
- `cost` - Message cost
|
|
162
|
+
- `currency` - Currency code
|
|
163
|
+
- `msg_follow_up_unique_code` - Unique tracking code
|
|
164
|
+
- `balance` - Account balance
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Error Handling
|
|
169
|
+
|
|
170
|
+
The SDK raises appropriate Ruby exceptions:
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
begin
|
|
174
|
+
sdk = CommsSdk::V1::CommsSDK.authenticate("", "") # Empty credentials
|
|
175
|
+
rescue ArgumentError => e
|
|
176
|
+
puts "Authentication error: #{e.message}"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
begin
|
|
180
|
+
sdk.send_sms([], "") # Empty numbers and message
|
|
181
|
+
rescue ArgumentError => e
|
|
182
|
+
puts "Validation error: #{e.message}"
|
|
183
|
+
end
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Thread Safety
|
|
189
|
+
|
|
190
|
+
The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
|
|
191
|
+
|
|
192
|
+
---
|
|
26
193
|
|
|
27
|
-
##
|
|
194
|
+
## Contributing
|
|
28
195
|
|
|
29
|
-
|
|
196
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
30
197
|
|
|
31
|
-
|
|
198
|
+
---
|
|
32
199
|
|
|
33
200
|
## License
|
|
34
201
|
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_tasks"
|
|
4
|
-
require "rspec/core/rake_task"
|
|
5
|
-
|
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
-
|
|
8
|
-
require "standard/rake"
|
|
9
|
-
|
|
10
|
-
task default: %i[spec standard]
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
+
|
|
8
|
+
require "standard/rake"
|
|
9
|
+
|
|
10
|
+
task default: %i[spec standard]
|
data/build_and_upload.sh
ADDED
data/lib/comms_sdk/v1/README.md
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
# CommsSdk Ruby Implementation
|
|
2
|
-
|
|
3
|
-
A Ruby implementation of the Communications SDK that follows the same patterns as the Python implementation and matches the Kotlin reference implementation.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Consistent API**: Matches the standardized interface across all language implementations
|
|
8
|
-
- **Authentication**: Uses `userName` and `apiKey` authentication pattern
|
|
9
|
-
- **Dual Methods**: Provides both simple boolean return methods and full response query methods
|
|
10
|
-
- **Error Handling**: Comprehensive error handling with proper Ruby exceptions
|
|
11
|
-
- **Validation**: Phone number validation and credential validation
|
|
12
|
-
- **Logging**: Proper error logging to stderr
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
Add this line to your application's Gemfile:
|
|
17
|
-
|
|
18
|
-
```ruby
|
|
19
|
-
gem 'comms_sdk'
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
And then execute:
|
|
23
|
-
|
|
24
|
-
$ bundle install
|
|
25
|
-
|
|
26
|
-
Or install it yourself as:
|
|
27
|
-
|
|
28
|
-
$ gem install comms_sdk
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
|
|
32
|
-
### Basic Authentication
|
|
33
|
-
|
|
34
|
-
```ruby
|
|
35
|
-
require 'comms_sdk'
|
|
36
|
-
|
|
37
|
-
# Authenticate with username and API key
|
|
38
|
-
sdk = CommsSdk.authenticate("your_username", "your_api_key")
|
|
39
|
-
|
|
40
|
-
# Or use the V1 module directly
|
|
41
|
-
sdk = CommsSdk::V1::CommsSDK.authenticate("your_username", "your_api_key")
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Sending SMS
|
|
45
|
-
|
|
46
|
-
```ruby
|
|
47
|
-
# Send SMS to a single number
|
|
48
|
-
success = sdk.send_sms("256712345678", "Hello from Ruby!")
|
|
49
|
-
|
|
50
|
-
# Send SMS to multiple numbers
|
|
51
|
-
success = sdk.send_sms(["256712345678", "256787654321"], "Hello to all!")
|
|
52
|
-
|
|
53
|
-
# Send SMS with custom sender ID and priority
|
|
54
|
-
success = sdk.send_sms(
|
|
55
|
-
"256712345678",
|
|
56
|
-
"Hello!",
|
|
57
|
-
sender_id: "MyApp",
|
|
58
|
-
priority: CommsSdk::V1::MessagePriority::HIGH
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
# Get full API response
|
|
62
|
-
response = sdk.query_send_sms(
|
|
63
|
-
["256712345678"],
|
|
64
|
-
"Hello!",
|
|
65
|
-
"MyApp",
|
|
66
|
-
CommsSdk::V1::MessagePriority::HIGHEST
|
|
67
|
-
)
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Checking Balance
|
|
71
|
-
|
|
72
|
-
```ruby
|
|
73
|
-
# Get balance as a float
|
|
74
|
-
balance = sdk.get_balance
|
|
75
|
-
puts "Balance: #{balance}"
|
|
76
|
-
|
|
77
|
-
# Get full balance response
|
|
78
|
-
response = sdk.query_balance
|
|
79
|
-
puts "Status: #{response.status}"
|
|
80
|
-
puts "Balance: #{response.balance}"
|
|
81
|
-
puts "Currency: #{response.currency}"
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Configuration
|
|
85
|
-
|
|
86
|
-
```ruby
|
|
87
|
-
# Use sandbox environment
|
|
88
|
-
CommsSdk::V1::CommsSDK.use_sandbox
|
|
89
|
-
|
|
90
|
-
# Use live server (default)
|
|
91
|
-
CommsSdk::V1::CommsSDK.use_live_server
|
|
92
|
-
|
|
93
|
-
# Set custom sender ID
|
|
94
|
-
sdk.with_sender_id("MyCustomSender")
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## API Reference
|
|
98
|
-
|
|
99
|
-
### CommsSdk::V1::CommsSDK
|
|
100
|
-
|
|
101
|
-
#### Class Methods
|
|
102
|
-
|
|
103
|
-
- `authenticate(user_name, api_key)` - Authenticate and return SDK instance
|
|
104
|
-
- `use_sandbox` - Switch to sandbox environment
|
|
105
|
-
- `use_live_server` - Switch to live environment
|
|
106
|
-
|
|
107
|
-
#### Instance Methods
|
|
108
|
-
|
|
109
|
-
- `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)` - Send SMS, returns boolean
|
|
110
|
-
- `query_send_sms(numbers, message, sender_id, priority)` - Send SMS, returns full ApiResponse
|
|
111
|
-
- `get_balance()` - Get account balance as float
|
|
112
|
-
- `query_balance()` - Get full balance response as ApiResponse
|
|
113
|
-
- `with_sender_id(sender_id)` - Set sender ID, returns self for chaining
|
|
114
|
-
|
|
115
|
-
#### Properties
|
|
116
|
-
|
|
117
|
-
- `api_key` - The API key used for authentication
|
|
118
|
-
- `user_name` - The username used for authentication
|
|
119
|
-
- `sender_id` - Current sender ID
|
|
120
|
-
- `is_authenticated` - Authentication status
|
|
121
|
-
|
|
122
|
-
### Models
|
|
123
|
-
|
|
124
|
-
#### MessagePriority
|
|
125
|
-
- `HIGHEST` - Priority "0"
|
|
126
|
-
- `HIGH` - Priority "1"
|
|
127
|
-
- `MEDIUM` - Priority "2"
|
|
128
|
-
- `LOW` - Priority "3"
|
|
129
|
-
- `LOWEST` - Priority "4"
|
|
130
|
-
|
|
131
|
-
#### ApiResponse
|
|
132
|
-
- `status` - Response status ("OK" or "Failed")
|
|
133
|
-
- `message` - Response message
|
|
134
|
-
- `cost` - Message cost
|
|
135
|
-
- `currency` - Currency code
|
|
136
|
-
- `msg_follow_up_unique_code` - Unique tracking code
|
|
137
|
-
- `balance` - Account balance
|
|
138
|
-
|
|
139
|
-
## Error Handling
|
|
140
|
-
|
|
141
|
-
The SDK raises appropriate Ruby exceptions:
|
|
142
|
-
|
|
143
|
-
```ruby
|
|
144
|
-
begin
|
|
145
|
-
sdk = CommsSdk.authenticate("", "") # Empty credentials
|
|
146
|
-
rescue ArgumentError => e
|
|
147
|
-
puts "Authentication error: #{e.message}"
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
begin
|
|
151
|
-
sdk.send_sms([], "") # Empty numbers and message
|
|
152
|
-
rescue ArgumentError => e
|
|
153
|
-
puts "Validation error: #{e.message}"
|
|
154
|
-
end
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Thread Safety
|
|
158
|
-
|
|
159
|
-
The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
|
|
160
|
-
|
|
161
|
-
## Contributing
|
|
162
|
-
|
|
163
|
-
Bug reports and pull requests are welcome on GitHub.
|
|
164
|
-
|
|
165
|
-
## License
|
|
166
|
-
|
|
1
|
+
# CommsSdk Ruby Implementation
|
|
2
|
+
|
|
3
|
+
A Ruby implementation of the Communications SDK that follows the same patterns as the Python implementation and matches the Kotlin reference implementation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Consistent API**: Matches the standardized interface across all language implementations
|
|
8
|
+
- **Authentication**: Uses `userName` and `apiKey` authentication pattern
|
|
9
|
+
- **Dual Methods**: Provides both simple boolean return methods and full response query methods
|
|
10
|
+
- **Error Handling**: Comprehensive error handling with proper Ruby exceptions
|
|
11
|
+
- **Validation**: Phone number validation and credential validation
|
|
12
|
+
- **Logging**: Proper error logging to stderr
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Add this line to your application's Gemfile:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'comms_sdk'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
$ bundle install
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
$ gem install comms_sdk
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Basic Authentication
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
require 'comms_sdk'
|
|
36
|
+
|
|
37
|
+
# Authenticate with username and API key
|
|
38
|
+
sdk = CommsSdk.authenticate("your_username", "your_api_key")
|
|
39
|
+
|
|
40
|
+
# Or use the V1 module directly
|
|
41
|
+
sdk = CommsSdk::V1::CommsSDK.authenticate("your_username", "your_api_key")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Sending SMS
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
# Send SMS to a single number
|
|
48
|
+
success = sdk.send_sms("256712345678", "Hello from Ruby!")
|
|
49
|
+
|
|
50
|
+
# Send SMS to multiple numbers
|
|
51
|
+
success = sdk.send_sms(["256712345678", "256787654321"], "Hello to all!")
|
|
52
|
+
|
|
53
|
+
# Send SMS with custom sender ID and priority
|
|
54
|
+
success = sdk.send_sms(
|
|
55
|
+
"256712345678",
|
|
56
|
+
"Hello!",
|
|
57
|
+
sender_id: "MyApp",
|
|
58
|
+
priority: CommsSdk::V1::MessagePriority::HIGH
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Get full API response
|
|
62
|
+
response = sdk.query_send_sms(
|
|
63
|
+
["256712345678"],
|
|
64
|
+
"Hello!",
|
|
65
|
+
"MyApp",
|
|
66
|
+
CommsSdk::V1::MessagePriority::HIGHEST
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Checking Balance
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
# Get balance as a float
|
|
74
|
+
balance = sdk.get_balance
|
|
75
|
+
puts "Balance: #{balance}"
|
|
76
|
+
|
|
77
|
+
# Get full balance response
|
|
78
|
+
response = sdk.query_balance
|
|
79
|
+
puts "Status: #{response.status}"
|
|
80
|
+
puts "Balance: #{response.balance}"
|
|
81
|
+
puts "Currency: #{response.currency}"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Configuration
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
# Use sandbox environment
|
|
88
|
+
CommsSdk::V1::CommsSDK.use_sandbox
|
|
89
|
+
|
|
90
|
+
# Use live server (default)
|
|
91
|
+
CommsSdk::V1::CommsSDK.use_live_server
|
|
92
|
+
|
|
93
|
+
# Set custom sender ID
|
|
94
|
+
sdk.with_sender_id("MyCustomSender")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API Reference
|
|
98
|
+
|
|
99
|
+
### CommsSdk::V1::CommsSDK
|
|
100
|
+
|
|
101
|
+
#### Class Methods
|
|
102
|
+
|
|
103
|
+
- `authenticate(user_name, api_key)` - Authenticate and return SDK instance
|
|
104
|
+
- `use_sandbox` - Switch to sandbox environment
|
|
105
|
+
- `use_live_server` - Switch to live environment
|
|
106
|
+
|
|
107
|
+
#### Instance Methods
|
|
108
|
+
|
|
109
|
+
- `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)` - Send SMS, returns boolean
|
|
110
|
+
- `query_send_sms(numbers, message, sender_id, priority)` - Send SMS, returns full ApiResponse
|
|
111
|
+
- `get_balance()` - Get account balance as float
|
|
112
|
+
- `query_balance()` - Get full balance response as ApiResponse
|
|
113
|
+
- `with_sender_id(sender_id)` - Set sender ID, returns self for chaining
|
|
114
|
+
|
|
115
|
+
#### Properties
|
|
116
|
+
|
|
117
|
+
- `api_key` - The API key used for authentication
|
|
118
|
+
- `user_name` - The username used for authentication
|
|
119
|
+
- `sender_id` - Current sender ID
|
|
120
|
+
- `is_authenticated` - Authentication status
|
|
121
|
+
|
|
122
|
+
### Models
|
|
123
|
+
|
|
124
|
+
#### MessagePriority
|
|
125
|
+
- `HIGHEST` - Priority "0"
|
|
126
|
+
- `HIGH` - Priority "1"
|
|
127
|
+
- `MEDIUM` - Priority "2"
|
|
128
|
+
- `LOW` - Priority "3"
|
|
129
|
+
- `LOWEST` - Priority "4"
|
|
130
|
+
|
|
131
|
+
#### ApiResponse
|
|
132
|
+
- `status` - Response status ("OK" or "Failed")
|
|
133
|
+
- `message` - Response message
|
|
134
|
+
- `cost` - Message cost
|
|
135
|
+
- `currency` - Currency code
|
|
136
|
+
- `msg_follow_up_unique_code` - Unique tracking code
|
|
137
|
+
- `balance` - Account balance
|
|
138
|
+
|
|
139
|
+
## Error Handling
|
|
140
|
+
|
|
141
|
+
The SDK raises appropriate Ruby exceptions:
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
begin
|
|
145
|
+
sdk = CommsSdk.authenticate("", "") # Empty credentials
|
|
146
|
+
rescue ArgumentError => e
|
|
147
|
+
puts "Authentication error: #{e.message}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
begin
|
|
151
|
+
sdk.send_sms([], "") # Empty numbers and message
|
|
152
|
+
rescue ArgumentError => e
|
|
153
|
+
puts "Validation error: #{e.message}"
|
|
154
|
+
end
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Thread Safety
|
|
158
|
+
|
|
159
|
+
The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
|
|
160
|
+
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
167
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -9,7 +9,7 @@ require_relative 'utils'
|
|
|
9
9
|
module CommsSdk
|
|
10
10
|
module V1
|
|
11
11
|
class CommsSDK
|
|
12
|
-
API_URL = "
|
|
12
|
+
API_URL = "https://comms-test.pahappa.net/api/v1/json/"
|
|
13
13
|
|
|
14
14
|
attr_reader :api_key, :user_name, :sender_id, :is_authenticated
|
|
15
15
|
|
|
@@ -30,12 +30,12 @@ module CommsSdk
|
|
|
30
30
|
|
|
31
31
|
def self.use_sandbox
|
|
32
32
|
remove_const(:API_URL) if const_defined?(:API_URL)
|
|
33
|
-
const_set(:API_URL, "
|
|
33
|
+
const_set(:API_URL, "https://comms-test.pahappa.net/api/v1/json")
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def self.use_live_server
|
|
37
37
|
remove_const(:API_URL) if const_defined?(:API_URL)
|
|
38
|
-
const_set(:API_URL, "
|
|
38
|
+
const_set(:API_URL, "https://comms-test.pahappa.net/api/v1/json")
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def set_authenticated
|
data/lib/comms_sdk/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module CommsSdk
|
|
4
|
-
VERSION = "1.0.
|
|
5
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CommsSdk
|
|
4
|
+
VERSION = "1.0.1"
|
|
5
|
+
end
|
data/lib/comms_sdk.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "comms_sdk/version"
|
|
4
|
-
require_relative "comms_sdk/v1/comms_sdk"
|
|
5
|
-
|
|
6
|
-
module CommsSdk
|
|
7
|
-
class Error < StandardError; end
|
|
8
|
-
|
|
9
|
-
# Convenience method to access the V1 SDK
|
|
10
|
-
def self.authenticate(user_name, api_key)
|
|
11
|
-
V1::CommsSDK.authenticate(user_name, api_key)
|
|
12
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "comms_sdk/version"
|
|
4
|
+
require_relative "comms_sdk/v1/comms_sdk"
|
|
5
|
+
|
|
6
|
+
module CommsSdk
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
# Convenience method to access the V1 SDK
|
|
10
|
+
def self.authenticate(user_name, api_key)
|
|
11
|
+
V1::CommsSDK.authenticate(user_name, api_key)
|
|
12
|
+
end
|
|
13
13
|
end
|
data/sig/comms_sdk.rbs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module CommsSdk
|
|
2
|
-
VERSION: String
|
|
3
|
-
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
|
4
|
-
end
|
|
1
|
+
module CommsSdk
|
|
2
|
+
VERSION: String
|
|
3
|
+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
|
4
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: comms_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- LICENSE.txt
|
|
22
22
|
- README.md
|
|
23
23
|
- Rakefile
|
|
24
|
+
- build_and_upload.sh
|
|
24
25
|
- lib/comms_sdk.rb
|
|
25
26
|
- lib/comms_sdk/v1/README.md
|
|
26
27
|
- lib/comms_sdk/v1/comms_sdk.rb
|