comms_sdk 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d62a3711780407daaa0294a755a59775499665b3b07ef3a5af9edcd849f32fdb
4
- data.tar.gz: 9dd7deca89b32b00f1a483e0dc5cb0738a3cf5a19406e9a73ea38111d3c7ed41
3
+ metadata.gz: f9ea74e1fd85fce61fa38b1b7fa2d488176f187596c91cd594026f553b866f52
4
+ data.tar.gz: 919d0b66b1f395aa8eade387e3e2330439fe542f2649aacb204278f067ecba73
5
5
  SHA512:
6
- metadata.gz: 4dc71be2eb0b4e17b2a46e530d57a3291ea1cf056549172afefd9b542b961c350ee3cf2528b8507ddd381cb69ebfeef31d1e4c0694b34d701746ae02f3f8d477
7
- data.tar.gz: 17cd00fbc6f6e3a3973402d6864c137839a5f975b315ce08852f99898d5431f2da1b89c95303c23457ebeb78427b0b08dd51f4116cf72ef009a49717d80d8fe7
6
+ metadata.gz: 10c5b114e2c6f02c5d8dd0f38c7a8843987471d64aa51f56369c4dbc1faf01760b548bfeee7400aaa154bc97566f4349bea1c05f8bddae5cf78204725cf7f8fc
7
+ data.tar.gz: e4ed0bbfab88defd40e25a6590034165efca6470b4379712efbc33fcb89295fdec5debfcaf5de60bfdf916422db256e340269a23e7c53f814b727a6494aeafec
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,199 @@
1
- # CommsSdk
1
+ # comms_sdk Ruby SDK
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/comms_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ **Version:** 1.1.0
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
22
+ Add this line to your application's Gemfile:
10
23
 
11
- Install the gem and add to the application's Gemfile by executing:
24
+ ```ruby
25
+ gem 'comms_sdk', '~> 1.1.0'
26
+ ```
27
+
28
+ And then execute:
12
29
 
13
30
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
31
+ bundle install
15
32
  ```
16
33
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
34
+ Or install it yourself as:
18
35
 
19
36
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
37
+ gem install comms_sdk
21
38
  ```
22
39
 
40
+ ---
41
+
23
42
  ## Usage
24
43
 
25
- TODO: Write usage instructions here
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
+ ```
91
+
92
+ ### Configuration
93
+
94
+ ```ruby
95
+ # Use sandbox environment
96
+ CommsSdk::V1::CommsSDK.use_sandbox
97
+
98
+ # Use live server (default)
99
+ CommsSdk::V1::CommsSDK.use_live_server
100
+
101
+ # Set custom sender ID
102
+ sdk.with_sender_id("MyCustomSender")
103
+ ```
104
+
105
+ ---
106
+
107
+ ## API Reference
108
+
109
+ ### CommsSdk::V1::CommsSDK
110
+
111
+ #### Class Methods
112
+
113
+ - `authenticate(user_name, api_key)`
114
+ Authenticate and return SDK instance.
115
+ - `use_sandbox`
116
+ Switch to sandbox environment.
117
+ - `use_live_server`
118
+ Switch to live environment.
119
+
120
+ #### Instance Methods
121
+
122
+ - `with_sender_id(sender_id)`
123
+ Set sender ID, returns self for chaining.
124
+ - `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)`
125
+ Send SMS, returns boolean.
126
+ - `query_send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)`
127
+ Same as `send_sms`, but returns the full ApiResponse.
128
+ - `get_balance`
129
+ Get account balance as float.
130
+ - `query_balance`
131
+ Get full balance response as ApiResponse.
132
+ - `set_authenticated`
133
+ Mark SDK as authenticated (internal use).
134
+
135
+ #### Attributes
136
+
137
+ - `api_key`
138
+ The API key used for authentication.
139
+ - `user_name`
140
+ The username used for authentication.
141
+ - `sender_id`
142
+ Current sender ID.
143
+ - `is_authenticated`
144
+ Authentication status.
145
+
146
+ ### Models
147
+
148
+ #### MessagePriority
149
+
150
+ - `MessagePriority::HIGHEST` - Priority "0"
151
+ - `MessagePriority::HIGH` - Priority "1"
152
+ - `MessagePriority::MEDIUM` - Priority "2"
153
+ - `MessagePriority::LOW` - Priority "3"
154
+ - `MessagePriority::LOWEST` - Priority "4"
155
+
156
+ #### ApiResponse
157
+
158
+ - `status` - Response status ("OK" or "Failed")
159
+ - `message` - Response message
160
+ - `cost` - Message cost (not always a whole number)
161
+ - `msg_follow_up_unique_code` - Unique tracking code
162
+ - `balance` - Account balance
163
+
164
+ ---
165
+
166
+ ## Error Handling
167
+
168
+ The SDK raises appropriate Ruby exceptions:
169
+
170
+ ```ruby
171
+ begin
172
+ sdk = CommsSdk::V1::CommsSDK.authenticate("", "") # Empty credentials
173
+ rescue ArgumentError => e
174
+ puts "Authentication error: #{e.message}"
175
+ end
176
+
177
+ begin
178
+ sdk.send_sms([], "") # Empty numbers and message
179
+ rescue ArgumentError => e
180
+ puts "Validation error: #{e.message}"
181
+ end
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Thread Safety
187
+
188
+ The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
189
+
190
+ ---
26
191
 
27
- ## Development
192
+ ## Contributing
28
193
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
194
+ Bug reports and pull requests are welcome on GitHub.
30
195
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
196
+ ---
32
197
 
33
198
  ## License
34
199
 
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]
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ rm -f ./*.gem
3
+ gem build comms_sdk.gemspec
4
+ GEM_HOST_API_KEY=rubygems_b64bca26f978b82cea4200d4e5d04d06444401f6cc340f27 gem push ./comms_sdk-*.gem
@@ -1,167 +1,165 @@
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
+ ```
82
+
83
+ ### Configuration
84
+
85
+ ```ruby
86
+ # Use sandbox environment
87
+ CommsSdk::V1::CommsSDK.use_sandbox
88
+
89
+ # Use live server (default)
90
+ CommsSdk::V1::CommsSDK.use_live_server
91
+
92
+ # Set custom sender ID
93
+ sdk.with_sender_id("MyCustomSender")
94
+ ```
95
+
96
+ ## API Reference
97
+
98
+ ### CommsSdk::V1::CommsSDK
99
+
100
+ #### Class Methods
101
+
102
+ - `authenticate(user_name, api_key)` - Authenticate and return SDK instance
103
+ - `use_sandbox` - Switch to sandbox environment
104
+ - `use_live_server` - Switch to live environment
105
+
106
+ #### Instance Methods
107
+
108
+ - `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)` - Send SMS, returns boolean
109
+ - `query_send_sms(numbers, message, sender_id, priority)` - Send SMS, returns full ApiResponse
110
+ - `get_balance()` - Get account balance as float
111
+ - `query_balance()` - Get full balance response as ApiResponse
112
+ - `with_sender_id(sender_id)` - Set sender ID, returns self for chaining
113
+
114
+ #### Properties
115
+
116
+ - `api_key` - The API key used for authentication
117
+ - `user_name` - The username used for authentication
118
+ - `sender_id` - Current sender ID
119
+ - `is_authenticated` - Authentication status
120
+
121
+ ### Models
122
+
123
+ #### MessagePriority
124
+ - `HIGHEST` - Priority "0"
125
+ - `HIGH` - Priority "1"
126
+ - `MEDIUM` - Priority "2"
127
+ - `LOW` - Priority "3"
128
+ - `LOWEST` - Priority "4"
129
+
130
+ #### ApiResponse
131
+ - `status` - Response status ("OK" or "Failed")
132
+ - `message` - Response message
133
+ - `cost` - Message cost (not always a whole number)
134
+ - `msg_follow_up_unique_code` - Unique tracking code
135
+ - `balance` - Account balance
136
+
137
+ ## Error Handling
138
+
139
+ The SDK raises appropriate Ruby exceptions:
140
+
141
+ ```ruby
142
+ begin
143
+ sdk = CommsSdk.authenticate("", "") # Empty credentials
144
+ rescue ArgumentError => e
145
+ puts "Authentication error: #{e.message}"
146
+ end
147
+
148
+ begin
149
+ sdk.send_sms([], "") # Empty numbers and message
150
+ rescue ArgumentError => e
151
+ puts "Validation error: #{e.message}"
152
+ end
153
+ ```
154
+
155
+ ## Thread Safety
156
+
157
+ The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub.
162
+
163
+ ## License
164
+
167
165
  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 = "http://176.58.101.43:8080/communications/api/v1/json/"
12
+ API_URL = "https://comms.egosms.co/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, "http://176.58.101.43:8080/communications/api/v1/json")
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, "http://176.58.101.43:8080/communications/api/v1/json")
38
+ const_set(:API_URL, "https://comms.egosms.co/api/v1/json")
39
39
  end
40
40
 
41
41
  def set_authenticated
@@ -47,10 +47,8 @@ module CommsSdk
47
47
  self
48
48
  end
49
49
 
50
- def send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)
51
- numbers = [numbers] if numbers.is_a?(String)
52
-
53
- api_response = query_send_sms(numbers, message, sender_id || @sender_id, priority)
50
+ def send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)
51
+ api_response = query_send_sms(numbers, message, sender_id: sender_id, priority: priority)
54
52
 
55
53
  if api_response.nil?
56
54
  puts "Failed to get a response from the server."
@@ -70,9 +68,12 @@ module CommsSdk
70
68
  end
71
69
  end
72
70
 
73
- def query_send_sms(numbers, message, sender_id, priority)
71
+ def query_send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)
74
72
  return nil if sdk_not_authenticated?
75
-
73
+
74
+ numbers = [numbers] if numbers.is_a?(String)
75
+ sender_id ||= @sender_id
76
+
76
77
  raise ArgumentError, "Numbers list cannot be empty" if numbers.nil? || numbers.empty?
77
78
  raise ArgumentError, "Message cannot be empty" if message.nil? || message.empty?
78
79
  raise ArgumentError, "Message cannot be a single character" if message.length == 1
@@ -96,7 +97,8 @@ module CommsSdk
96
97
  api_request = ApiRequest.new(
97
98
  method: "SendSms",
98
99
  userdata: UserData.new(@user_name, @api_key),
99
- msgdata: message_models
100
+ msgdata: message_models,
101
+ wallet_type: WalletType::LOCAL
100
102
  )
101
103
 
102
104
  begin
@@ -113,14 +115,17 @@ module CommsSdk
113
115
  end
114
116
  end
115
117
 
116
- def query_balance
118
+ def query_balance(wallet_type: nil)
117
119
  return nil if sdk_not_authenticated?
118
-
120
+
121
+ wallet_type ||= WalletType::LOCAL
122
+
119
123
  api_request = ApiRequest.new(
120
124
  method: "Balance",
121
- userdata: UserData.new(@user_name, @api_key)
125
+ userdata: UserData.new(@user_name, @api_key),
126
+ wallet_type: wallet_type
122
127
  )
123
-
128
+
124
129
  begin
125
130
  response = make_http_request(api_request)
126
131
  ApiResponse.from_hash(JSON.parse(response.body))
@@ -129,8 +134,8 @@ module CommsSdk
129
134
  end
130
135
  end
131
136
 
132
- def get_balance
133
- response = query_balance
137
+ def get_balance(wallet_type: nil)
138
+ response = query_balance(wallet_type: wallet_type)
134
139
  return nil if response.nil? || response.balance.nil?
135
140
 
136
141
  begin
@@ -51,6 +51,28 @@ module CommsSdk
51
51
  LOWEST = new("4")
52
52
  end
53
53
 
54
+ class WalletType
55
+ attr_reader :value
56
+
57
+ def initialize(value)
58
+ @value = value
59
+ end
60
+
61
+ def self.from_value(text)
62
+ case text
63
+ when "Local"
64
+ LOCAL
65
+ when "International"
66
+ INTERNATIONAL
67
+ else
68
+ raise ArgumentError, "Unknown wallet type value: #{text}"
69
+ end
70
+ end
71
+
72
+ LOCAL = new("Local")
73
+ INTERNATIONAL = new("International")
74
+ end
75
+
54
76
  class UserData
55
77
  attr_reader :username, :apikey
56
78
 
@@ -96,12 +118,13 @@ module CommsSdk
96
118
  end
97
119
 
98
120
  class ApiRequest
99
- attr_reader :method, :userdata, :msgdata
121
+ attr_reader :method, :userdata, :msgdata, :wallet_type
100
122
 
101
- def initialize(method:, userdata:, msgdata: nil)
123
+ def initialize(method:, userdata:, msgdata: nil, wallet_type: nil)
102
124
  @method = method
103
125
  @userdata = userdata
104
126
  @msgdata = msgdata
127
+ @wallet_type = wallet_type
105
128
  end
106
129
 
107
130
  def to_hash
@@ -110,6 +133,7 @@ module CommsSdk
110
133
  "userdata" => @userdata.to_hash
111
134
  }
112
135
  hash["msgdata"] = @msgdata.map(&:to_hash) if @msgdata
136
+ hash["walletType"] = @wallet_type.value if @wallet_type
113
137
  hash
114
138
  end
115
139
 
@@ -119,13 +143,12 @@ module CommsSdk
119
143
  end
120
144
 
121
145
  class ApiResponse
122
- attr_reader :status, :message, :cost, :currency, :msg_follow_up_unique_code, :balance
146
+ attr_reader :status, :message, :cost, :msg_follow_up_unique_code, :balance
123
147
 
124
- def initialize(status:, message: nil, cost: nil, currency: nil, msg_follow_up_unique_code: nil, balance: nil)
148
+ def initialize(status:, message: nil, cost: nil, msg_follow_up_unique_code: nil, balance: nil)
125
149
  @status = status
126
150
  @message = message
127
151
  @cost = cost
128
- @currency = currency
129
152
  @msg_follow_up_unique_code = msg_follow_up_unique_code
130
153
  @balance = balance
131
154
  end
@@ -135,7 +158,6 @@ module CommsSdk
135
158
  status: hash["Status"],
136
159
  message: hash["Message"],
137
160
  cost: hash["Cost"],
138
- currency: hash["Currency"],
139
161
  msg_follow_up_unique_code: hash["MsgFollowUpUniqueCode"],
140
162
  balance: hash["Balance"]
141
163
  )
@@ -146,7 +168,6 @@ module CommsSdk
146
168
  "Status" => @status,
147
169
  "Message" => @message,
148
170
  "Cost" => @cost,
149
- "Currency" => @currency,
150
171
  "MsgFollowUpUniqueCode" => @msg_follow_up_unique_code,
151
172
  "Balance" => @balance
152
173
  }.compact
@@ -63,7 +63,8 @@ module CommsSdk
63
63
  def self.valid_credential?(sdk)
64
64
  api_request = ApiRequest.new(
65
65
  method: "Balance",
66
- userdata: UserData.new(sdk.user_name, sdk.api_key)
66
+ userdata: UserData.new(sdk.user_name, sdk.api_key),
67
+ wallet_type: WalletType::LOCAL
67
68
  )
68
69
 
69
70
  begin
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module CommsSdk
4
- VERSION = "1.0.0"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module CommsSdk
4
+ VERSION = "1.1.0"
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.0
4
+ version: 1.1.0
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