comms_sdk 1.0.1 → 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: 2bd645fc9d43ee7901bbee4f47d065cecb985dab95eb167bacec0e9984df888d
4
- data.tar.gz: 2ab419f94ce8b2f7966aeb0aa9ab568fefc4078378e9eb5bc8ef6c7119f3e87e
3
+ metadata.gz: f9ea74e1fd85fce61fa38b1b7fa2d488176f187596c91cd594026f553b866f52
4
+ data.tar.gz: 919d0b66b1f395aa8eade387e3e2330439fe542f2649aacb204278f067ecba73
5
5
  SHA512:
6
- metadata.gz: 599836f2e32cf109d8829689fe6b86459012378b0602d436cd69b6f8362e201d4900887b4caf589b20e8d85b6cbeac4ce6362696c1c55e6b976324c3bdb00e24
7
- data.tar.gz: f6fb82669a9a5022574e207fec635a293ea948bacd368e0aa2fa7e6831cb0e75a08652e89897bf3fee189b5f33379b1c41e4165ad142fc9260de1fe9a435bbbc
6
+ metadata.gz: 10c5b114e2c6f02c5d8dd0f38c7a8843987471d64aa51f56369c4dbc1faf01760b548bfeee7400aaa154bc97566f4349bea1c05f8bddae5cf78204725cf7f8fc
7
+ data.tar.gz: e4ed0bbfab88defd40e25a6590034165efca6470b4379712efbc33fcb89295fdec5debfcaf5de60bfdf916422db256e340269a23e7c53f814b727a6494aeafec
data/README.md CHANGED
@@ -2,7 +2,7 @@
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
- **Version:** 1.0.1
5
+ **Version:** 1.1.0
6
6
 
7
7
  ---
8
8
 
@@ -22,7 +22,7 @@ A Ruby implementation of the CommsSDK for sending SMS and managing communication
22
22
  Add this line to your application's Gemfile:
23
23
 
24
24
  ```ruby
25
- gem 'comms_sdk', '~> 1.0.1'
25
+ gem 'comms_sdk', '~> 1.1.0'
26
26
  ```
27
27
 
28
28
  And then execute:
@@ -87,7 +87,6 @@ puts "Balance: #{balance}"
87
87
  response = sdk.query_balance
88
88
  puts "Status: #{response.status}"
89
89
  puts "Balance: #{response.balance}"
90
- puts "Currency: #{response.currency}"
91
90
  ```
92
91
 
93
92
  ### Configuration
@@ -122,10 +121,10 @@ sdk.with_sender_id("MyCustomSender")
122
121
 
123
122
  - `with_sender_id(sender_id)`
124
123
  Set sender ID, returns self for chaining.
125
- - `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGHEST)`
124
+ - `send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)`
126
125
  Send SMS, returns boolean.
127
- - `query_send_sms(numbers, message, sender_id, priority)`
128
- Send SMS, returns full ApiResponse.
126
+ - `query_send_sms(numbers, message, sender_id: nil, priority: MessagePriority::HIGH)`
127
+ Same as `send_sms`, but returns the full ApiResponse.
129
128
  - `get_balance`
130
129
  Get account balance as float.
131
130
  - `query_balance`
@@ -158,8 +157,7 @@ sdk.with_sender_id("MyCustomSender")
158
157
 
159
158
  - `status` - Response status ("OK" or "Failed")
160
159
  - `message` - Response message
161
- - `cost` - Message cost
162
- - `currency` - Currency code
160
+ - `cost` - Message cost (not always a whole number)
163
161
  - `msg_follow_up_unique_code` - Unique tracking code
164
162
  - `balance` - Account balance
165
163
 
data/build_and_upload.sh CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/bin/bash
2
+ rm -f ./*.gem
2
3
  gem build comms_sdk.gemspec
3
4
  GEM_HOST_API_KEY=rubygems_b64bca26f978b82cea4200d4e5d04d06444401f6cc340f27 gem push ./comms_sdk-*.gem
@@ -78,7 +78,6 @@ puts "Balance: #{balance}"
78
78
  response = sdk.query_balance
79
79
  puts "Status: #{response.status}"
80
80
  puts "Balance: #{response.balance}"
81
- puts "Currency: #{response.currency}"
82
81
  ```
83
82
 
84
83
  ### Configuration
@@ -131,8 +130,7 @@ sdk.with_sender_id("MyCustomSender")
131
130
  #### ApiResponse
132
131
  - `status` - Response status ("OK" or "Failed")
133
132
  - `message` - Response message
134
- - `cost` - Message cost
135
- - `currency` - Currency code
133
+ - `cost` - Message cost (not always a whole number)
136
134
  - `msg_follow_up_unique_code` - Unique tracking code
137
135
  - `balance` - Account balance
138
136
 
@@ -9,7 +9,7 @@ require_relative 'utils'
9
9
  module CommsSdk
10
10
  module V1
11
11
  class CommsSDK
12
- API_URL = "https://comms-test.pahappa.net/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
 
@@ -35,7 +35,7 @@ module CommsSdk
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, "https://comms-test.pahappa.net/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
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommsSdk
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  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.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel