africastalking-ruby 2.1.8 → 2.2.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 +4 -4
- data/Gemfile.lock +152 -91
- data/README.md +16 -209
- data/africastalking-ruby.gemspec +5 -5
- data/lib/AfricasTalking/Mobiledata.rb +159 -0
- data/lib/AfricasTalking/version.rb +1 -1
- data/lib/AfricasTalking.rb +22 -15
- metadata +21 -27
- data/lib/AfricasTalking/Payments.rb +0 -688
@@ -0,0 +1,159 @@
|
|
1
|
+
class Mobiledata
|
2
|
+
include AfricasTalking
|
3
|
+
HTTP_CREATED = 201
|
4
|
+
HTTP_OK = 200
|
5
|
+
|
6
|
+
def initialize username, apikey
|
7
|
+
@username = username
|
8
|
+
@apikey = apikey
|
9
|
+
end
|
10
|
+
|
11
|
+
def send options
|
12
|
+
url = getMobileDataUrl()
|
13
|
+
|
14
|
+
validateParamsPresence? options, %w(productName)
|
15
|
+
recipients = options['recipients'].map do |item|
|
16
|
+
required_params = %w(phoneNumber quantity unit validity)
|
17
|
+
if item['metadata'].is_a?(Hash)
|
18
|
+
required_params << 'metadata'
|
19
|
+
end
|
20
|
+
|
21
|
+
validateParamsPresence?(item, required_params)
|
22
|
+
item
|
23
|
+
end
|
24
|
+
|
25
|
+
post_body = {
|
26
|
+
'username' => @username,
|
27
|
+
'productName' => options['productName'],
|
28
|
+
'recipients' => recipients,
|
29
|
+
}
|
30
|
+
|
31
|
+
idempotency_key = options['idempotencyKey'].to_s if options['idempotencyKey']
|
32
|
+
|
33
|
+
post_body['idempotencyKey'] = idempotency_key if idempotency_key
|
34
|
+
|
35
|
+
response = sendJSONRequest(url, post_body, idempotency_key)
|
36
|
+
|
37
|
+
if (@response_code == HTTP_CREATED)
|
38
|
+
responses = JSON.parse(response, :quirky_mode =>true)
|
39
|
+
|
40
|
+
if (responses['entries'].length > 0)
|
41
|
+
|
42
|
+
results = responses['entries'].collect{ |data|
|
43
|
+
|
44
|
+
MobileDataResponse.new data['phoneNumber'], data['provider'], data['status'], data['transactionId'], data['value']
|
45
|
+
}
|
46
|
+
|
47
|
+
return results
|
48
|
+
else
|
49
|
+
raise AfricasTalkingException, responses['errorMessage']
|
50
|
+
end
|
51
|
+
raise AfricasTalkingException, response
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def findTransaction options
|
56
|
+
validateParamsPresence? options, ['transactionId']
|
57
|
+
parameters = {
|
58
|
+
'username' => @username,
|
59
|
+
'transactionId' => options['transactionId']
|
60
|
+
}
|
61
|
+
url = getFindTransactionUrl()
|
62
|
+
response = sendJSONRequest(url, parameters, true, false)
|
63
|
+
if (@response_code == HTTP_OK)
|
64
|
+
resultObj = JSON.parse(response, :quirky_mode =>true)
|
65
|
+
transactionData = nil
|
66
|
+
if resultObj['status'] === 'Success'
|
67
|
+
transactionData = TransactionData.new resultObj['data']['requestMetadata'], resultObj['data']['sourceType'],resultObj['data']['source'], resultObj['data']['provider'], resultObj['data']['destinationType'],resultObj['data']['description'],
|
68
|
+
resultObj['data']['providerChannel'], resultObj['data']['providerRefId'], resultObj['data']['providerMetadata'],resultObj['data']['status'], resultObj['data']['productName'], resultObj['data']['category'],
|
69
|
+
resultObj['data']['transactionDate'], resultObj['data']['destination'], resultObj['data']['value'], resultObj['data']['transactionId'], resultObj['data']['creationTime']
|
70
|
+
end
|
71
|
+
return FindTransactionResponse.new resultObj['status'], transactionData
|
72
|
+
end
|
73
|
+
raise AfricasTalkingException, response
|
74
|
+
end
|
75
|
+
|
76
|
+
def fetchWalletBalance
|
77
|
+
parameters = { 'username' => @username }
|
78
|
+
url = getFetchWalletBalanceUrl()
|
79
|
+
response = sendJSONRequest(url, parameters, true, false)
|
80
|
+
if (@response_code == HTTP_OK)
|
81
|
+
resultObj = JSON.parse(response, :quirky_mode =>true)
|
82
|
+
|
83
|
+
return FetchWalletBalanceResponse.new resultObj['status'], resultObj['balance']
|
84
|
+
end
|
85
|
+
raise AfricasTalkingException, response
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
def getMobileDataUrl()
|
90
|
+
return getApiHost() + "/mobile/data/request"
|
91
|
+
end
|
92
|
+
|
93
|
+
def getFindTransactionUrl()
|
94
|
+
return getApiHost() + "/query/transaction/find"
|
95
|
+
end
|
96
|
+
|
97
|
+
def getFetchWalletBalanceUrl()
|
98
|
+
return getApiHost() + "/query/wallet/balance"
|
99
|
+
end
|
100
|
+
|
101
|
+
def getApiHost()
|
102
|
+
if(@username == "sandbox")
|
103
|
+
return "https://bundles.sandbox.africastalking.com"
|
104
|
+
else
|
105
|
+
return "https://bundles.africastalking.com"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class MobileDataResponse
|
111
|
+
attr_reader :phoneNumber, :provider, :status, :transactionId, :value
|
112
|
+
|
113
|
+
def initialize phoneNumber_, provider_, status_, transactionId_, value_
|
114
|
+
@phoneNumber = phoneNumber_
|
115
|
+
@provider = provider_
|
116
|
+
@status = status_
|
117
|
+
@transactionId = transactionId_
|
118
|
+
@value = value_
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class FetchWalletBalanceResponse
|
123
|
+
attr_reader :status, :balance
|
124
|
+
def initialize status_, balance_
|
125
|
+
@status = status_
|
126
|
+
@balance = balance_
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class FindTransactionResponse
|
131
|
+
attr_reader :status, :transactionData
|
132
|
+
def initialize status_, transactionData_
|
133
|
+
@status = status_
|
134
|
+
@transactionData = transactionData_
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class TransactionData
|
139
|
+
attr_reader :requestMetadata, :sourceType, :source, :provider, :destinationType, :description, :providerChannel, :providerRefId, :providerMetadata, :status, :productName, :category, :transactionDate, :destination, :value, :transactionId, :creationTime
|
140
|
+
def initialize requestMetadata_, sourceType_, source_, provider_, destinationType_, description_, providerChannel_, providerRefId_, providerMetadata_, status_, productName_, category_, transactionDate_, destination_, value_, transactionId_, creationTime_
|
141
|
+
@requestMetadata =requestMetadata_
|
142
|
+
@sourceType = sourceType_
|
143
|
+
@source = source_
|
144
|
+
@provider = provider_
|
145
|
+
@destinationType = destinationType_
|
146
|
+
@description = description_
|
147
|
+
@providerChannel = providerChannel_
|
148
|
+
@providerRefId = providerRefId_
|
149
|
+
@providerMetadata = providerMetadata_
|
150
|
+
@status = status_
|
151
|
+
@productName = productName_
|
152
|
+
@category = category_
|
153
|
+
@transactionDate = transactionDate_
|
154
|
+
@destination = destination_
|
155
|
+
@value = value_
|
156
|
+
@transactionId = transactionId_
|
157
|
+
@creationTime = creationTime_
|
158
|
+
end
|
159
|
+
end
|
data/lib/AfricasTalking.rb
CHANGED
@@ -2,7 +2,7 @@ require "AfricasTalking/version"
|
|
2
2
|
require 'httparty'
|
3
3
|
require "AfricasTalking/Sms"
|
4
4
|
require "AfricasTalking/Airtime"
|
5
|
-
require "AfricasTalking/
|
5
|
+
require "AfricasTalking/Mobiledata"
|
6
6
|
require "AfricasTalking/Voice"
|
7
7
|
require "AfricasTalking/Token"
|
8
8
|
require "AfricasTalking/Application"
|
@@ -17,29 +17,29 @@ module AfricasTalking
|
|
17
17
|
attr_accessor :username, :apikey
|
18
18
|
def initialize username, apikey
|
19
19
|
@username = username
|
20
|
-
@apikey = apikey
|
20
|
+
@apikey = apikey
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def sms
|
24
|
-
return Sms.new @username, @apikey
|
24
|
+
return Sms.new @username, @apikey
|
25
25
|
end
|
26
|
-
|
27
|
-
def
|
28
|
-
return
|
26
|
+
|
27
|
+
def mobiledata
|
28
|
+
return Mobiledata.new @username, @apikey
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def airtime
|
32
32
|
return Airtime.new @username, @apikey
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def voice
|
36
36
|
return Voice.new @username, @apikey
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def token
|
40
40
|
return Token.new @username, @apikey
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def application
|
44
44
|
return Application.new @username, @apikey
|
45
45
|
end
|
@@ -54,8 +54,8 @@ module AfricasTalking
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
|
-
private
|
58
|
-
|
57
|
+
private
|
58
|
+
|
59
59
|
def sendNormalRequest url_, data_ = nil
|
60
60
|
uri = URI.parse(url_)
|
61
61
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -78,7 +78,7 @@ module AfricasTalking
|
|
78
78
|
return response.body
|
79
79
|
end
|
80
80
|
|
81
|
-
def sendJSONRequest url_, data_, get_request = false
|
81
|
+
def sendJSONRequest url_, data_, get_request = false, idempotency_key = nil
|
82
82
|
uri = URI.parse(url_)
|
83
83
|
http = Net::HTTP.new(uri.host, uri.port)
|
84
84
|
http.use_ssl = true
|
@@ -88,11 +88,18 @@ module AfricasTalking
|
|
88
88
|
else
|
89
89
|
req = Net::HTTP::Post.new(uri.request_uri, 'Content-Type'=>"application/json")
|
90
90
|
req.body = data_.to_json
|
91
|
+
|
91
92
|
end
|
92
|
-
|
93
|
+
|
93
94
|
req["apikey"] = @apikey
|
94
95
|
req["Accept"] = "application/json"
|
96
|
+
|
97
|
+
if idempotency_key
|
98
|
+
req['Idempotency-Key'] = idempotency_key
|
99
|
+
end
|
100
|
+
|
95
101
|
response = http.request(req)
|
102
|
+
|
96
103
|
if (DEBUG)
|
97
104
|
puts "Full response #{response.body}"
|
98
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: africastalking-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Mwirigi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.5.5
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.5.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,36 +56,30 @@ dependencies:
|
|
56
56
|
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.7'
|
62
59
|
- - ">="
|
63
60
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
61
|
+
version: 6.1.0
|
65
62
|
type: :development
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
|
-
- - "~>"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '3.7'
|
72
66
|
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
68
|
+
version: 6.1.0
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: rubocop
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
|
-
- - "
|
73
|
+
- - ">="
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
75
|
+
version: 1.60.1
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
|
-
- - "
|
80
|
+
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
82
|
+
version: 1.60.1
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: pry
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,16 +98,16 @@ dependencies:
|
|
104
98
|
name: httparty
|
105
99
|
requirement: !ruby/object:Gem::Requirement
|
106
100
|
requirements:
|
107
|
-
- -
|
101
|
+
- - ">="
|
108
102
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
103
|
+
version: 0.21.0
|
110
104
|
type: :runtime
|
111
105
|
prerelease: false
|
112
106
|
version_requirements: !ruby/object:Gem::Requirement
|
113
107
|
requirements:
|
114
|
-
- -
|
108
|
+
- - ">="
|
115
109
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
110
|
+
version: 0.21.0
|
117
111
|
description: ''
|
118
112
|
email:
|
119
113
|
- mmwirigi@africastalking.com
|
@@ -135,7 +129,7 @@ files:
|
|
135
129
|
- lib/AfricasTalking.rb
|
136
130
|
- lib/AfricasTalking/Airtime.rb
|
137
131
|
- lib/AfricasTalking/Application.rb
|
138
|
-
- lib/AfricasTalking/
|
132
|
+
- lib/AfricasTalking/Mobiledata.rb
|
139
133
|
- lib/AfricasTalking/Sms.rb
|
140
134
|
- lib/AfricasTalking/Token.rb
|
141
135
|
- lib/AfricasTalking/Voice.rb
|
@@ -144,7 +138,7 @@ homepage: https://africastalking.com
|
|
144
138
|
licenses:
|
145
139
|
- MIT
|
146
140
|
metadata: {}
|
147
|
-
post_install_message:
|
141
|
+
post_install_message:
|
148
142
|
rdoc_options: []
|
149
143
|
require_paths:
|
150
144
|
- lib
|
@@ -159,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
153
|
- !ruby/object:Gem::Version
|
160
154
|
version: '0'
|
161
155
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
156
|
+
rubygems_version: 3.5.5
|
157
|
+
signing_key:
|
164
158
|
specification_version: 4
|
165
159
|
summary: Simple gem that helps you build integrations with AfricasTalking
|
166
160
|
test_files: []
|