t2_airtime 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -2
- data/app/controllers/t2_airtime/accounts_controller.rb +15 -0
- data/app/controllers/t2_airtime/application_controller.rb +46 -0
- data/app/controllers/t2_airtime/countries_controller.rb +20 -0
- data/app/controllers/t2_airtime/operators_controller.rb +26 -0
- data/app/controllers/t2_airtime/products_controller.rb +21 -0
- data/app/controllers/t2_airtime/transactions_controller.rb +48 -0
- data/config/routes.rb +5 -6
- data/lib/t2_airtime/api.rb +279 -277
- data/lib/t2_airtime/base.rb +30 -29
- data/lib/t2_airtime/engine.rb +10 -11
- data/lib/t2_airtime/errors.rb +85 -89
- data/lib/t2_airtime/reply.rb +57 -39
- data/lib/t2_airtime/request.rb +70 -65
- data/lib/t2_airtime/serializer.rb +294 -313
- data/lib/t2_airtime/url.rb +6 -6
- data/lib/t2_airtime/util.rb +28 -30
- data/lib/t2_airtime/version.rb +1 -1
- data/lib/t2_airtime.rb +13 -14
- data/spec/dummy/bin/setup +0 -1
- data/spec/dummy/config/application.rb +20 -9
- data/spec/dummy/config/environments/development.rb +2 -2
- data/spec/dummy/config/environments/production.rb +2 -3
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/puma.rb +3 -3
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/config/spring.rb +2 -2
- data/spec/dummy/log/development.log +6942 -0
- data/spec/dummy/log/production.log +8 -0
- data/spec/dummy/tmp/cache/361/BB0/accounts +0 -0
- data/spec/dummy/tmp/cache/3DD/470/countries +0 -0
- data/spec/dummy/tmp/cache/446/4A0/products%2F4 +0 -0
- data/spec/dummy/tmp/cache/4AD/6A0/products%2F137 +0 -0
- data/spec/dummy/tmp/cache/4B2/750/products%2F439 +0 -0
- data/spec/dummy/tmp/cache/4DA/3C0/products%2F2105 +0 -0
- data/spec/dummy/tmp/cache/4DD/4D0/products%2F2720 +0 -0
- data/spec/dummy/tmp/cache/4DE/470/products%2F1524 +0 -0
- data/spec/dummy/tmp/cache/4DE/490/products%2F1623 +0 -0
- data/spec/dummy/tmp/cache/4DE/500/products%2F2901 +0 -0
- data/spec/dummy/tmp/cache/4DF/460/products%2F2074 +0 -0
- data/spec/dummy/tmp/cache/4E0/470/products%2F2075 +0 -0
- data/spec/dummy/tmp/cache/4E2/480/products%2F2149 +0 -0
- data/spec/dummy/tmp/cache/4E2/500/products%2F1573 +0 -0
- data/spec/dummy/tmp/cache/4E4/500/products%2F2448 +0 -0
- data/spec/dummy/tmp/cache/4E4/530/products%2F1827 +0 -0
- data/spec/dummy/tmp/cache/4E5/570/products%2F1693 +0 -0
- data/spec/dummy/tmp/cache/4E5/5B0/products%2F1972 +0 -0
- data/spec/dummy/tmp/cache/4E7/580/products%2F1767 +0 -0
- data/spec/dummy/tmp/cache/4EB/5E0/products%2F1789 +0 -0
- data/spec/dummy/tmp/cache/4EB/5F0/products%2F1879 +0 -0
- data/spec/dummy/tmp/cache/4EC/610/products%2F1889 +0 -0
- data/spec/dummy/tmp/cache/515/9E0/operators%2F701 +0 -0
- data/spec/dummy/tmp/cache/518/A50/operators%2F740 +0 -0
- data/spec/dummy/tmp/cache/519/A20/operators%2F705 +0 -0
- data/spec/dummy/tmp/cache/51A/A70/operators%2F661 +0 -0
- data/spec/dummy/tmp/cache/51C/A90/operators%2F663 +0 -0
- data/spec/dummy/tmp/cache/51C/AB0/operators%2F681 +0 -0
- data/spec/dummy/tmp/cache/51D/AA0/operators%2F664 +0 -0
- data/spec/dummy/tmp/cache/51D/AC0/operators%2F844 +0 -0
- data/spec/dummy/tmp/cache/51D/AD0/operators%2F691 +0 -0
- data/spec/dummy/tmp/cache/51F/AE0/operators%2F684 +0 -0
- data/spec/dummy/tmp/cache/521/AE0/operators%2F668 +0 -0
- data/spec/dummy/tmp/cache/521/AF0/operators%2F677 +0 -0
- data/spec/dummy/tmp/cache/522/AF0/operators%2F669 +0 -0
- data/spec/dummy/tmp/cache/522/B00/operators%2F678 +0 -0
- data/spec/dummy/tmp/cache/523/B10/operators%2F679 +0 -0
- data/spec/dummy/tmp/cache/523/B50/operators%2F796 +0 -0
- data/spec/dummy/tmp/cache/769/350/accounts%2Fcurrency +1 -0
- data/spec/dummy/tmp/cache/8B4/E50/countries%2Fserializer +167 -0
- data/spec/dummy/tmp/cache/91D/3D0/products%2F4%2Fserializer +17 -0
- data/spec/dummy/tmp/cache/984/980/products%2F137%2Fserializer +28 -0
- data/spec/dummy/tmp/cache/989/E40/products%2F439%2Fserializer +11 -0
- data/spec/dummy/tmp/cache/9B1/B30/products%2F2105%2Fserializer +18 -0
- data/spec/dummy/tmp/cache/9B4/EB0/products%2F2720%2Fserializer +19 -0
- data/spec/dummy/tmp/cache/9B5/F20/products%2F1524%2Fserializer +14 -0
- data/spec/dummy/tmp/cache/9B5/F40/products%2F1623%2Fserializer +33 -0
- data/spec/dummy/tmp/cache/9B5/FB0/products%2F2901%2Fserializer +9 -0
- data/spec/dummy/tmp/cache/9B6/FE0/products%2F2074%2Fserializer +17 -0
- data/spec/dummy/tmp/cache/9B7/0C0/products%2F2075%2Fserializer +17 -0
- data/spec/dummy/tmp/cache/9B9/270/products%2F2149%2Fserializer +8 -0
- data/spec/dummy/tmp/cache/9B9/2F0/products%2F1573%2Fserializer +56 -0
- data/spec/dummy/tmp/cache/9BB/4C0/products%2F1827%2Fserializer +35 -0
- data/spec/dummy/tmp/cache/9BC/5D0/products%2F1693%2Fserializer +17 -0
- data/spec/dummy/tmp/cache/9BC/610/products%2F1972%2Fserializer +10 -0
- data/spec/dummy/tmp/cache/9BE/780/products%2F1767%2Fserializer +27 -0
- data/spec/dummy/tmp/cache/9C2/B20/products%2F1789%2Fserializer +52 -0
- data/spec/dummy/tmp/cache/9C2/B30/products%2F1879%2Fserializer +28 -0
- data/spec/dummy/tmp/cache/9C3/C20/products%2F1889%2Fserializer +46 -0
- data/spec/dummy/tmp/cache/9EC/140/operators%2F701%2Fserializer +13 -0
- data/spec/dummy/tmp/cache/9EF/420/operators%2F740%2Fserializer +9 -0
- data/spec/dummy/tmp/cache/9F0/4C0/operators%2F705%2Fserializer +4 -0
- data/spec/dummy/tmp/cache/9F1/5E0/operators%2F661%2Fserializer +6 -0
- data/spec/dummy/tmp/cache/9F3/7A0/operators%2F663%2Fserializer +4 -0
- data/spec/dummy/tmp/cache/9F3/7C0/operators%2F681%2Fserializer +3 -0
- data/spec/dummy/tmp/cache/9F4/880/operators%2F664%2Fserializer +2 -0
- data/spec/dummy/tmp/cache/9F4/8A0/operators%2F844%2Fserializer +10 -0
- data/spec/dummy/tmp/cache/9F4/8B0/operators%2F691%2Fserializer +8 -0
- data/spec/dummy/tmp/cache/9F6/A60/operators%2F684%2Fserializer +2 -0
- data/spec/dummy/tmp/cache/9F8/C00/operators%2F668%2Fserializer +4 -0
- data/spec/dummy/tmp/cache/9F8/C10/operators%2F677%2Fserializer +5 -0
- data/spec/dummy/tmp/cache/9F9/CE0/operators%2F669%2Fserializer +6 -0
- data/spec/dummy/tmp/cache/9F9/CF0/operators%2F678%2Fserializer +14 -0
- data/spec/dummy/tmp/cache/9FA/DD0/operators%2F679%2Fserializer +4 -0
- data/spec/dummy/tmp/cache/9FA/E10/operators%2F796%2Fserializer +3 -0
- data/spec/dummy/tmp/caching-dev.txt +0 -0
- data/spec/rails_helper.rb +1 -1
- data/spec/spec_helper.rb +47 -49
- data/spec/t2_airtime_spec.rb +179 -181
- metadata +176 -3
- data/app/controllers/t2_airtime/airtime_controller.rb +0 -105
@@ -1,313 +1,294 @@
|
|
1
|
-
module T2Airtime
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
},
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
},
|
284
|
-
{
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
type: "products",
|
296
|
-
id: Integer(data[:product_requested]),
|
297
|
-
attributes: {
|
298
|
-
"name": "#{data[:product_requested]}#{data[:destination_currency]}",
|
299
|
-
"currency": data[:destination_currency],
|
300
|
-
"wholesale-price": data[:wholesale_price],
|
301
|
-
"retail-price": data[:retail_price],
|
302
|
-
"local-price": Float(data[:product_requested])
|
303
|
-
}
|
304
|
-
}
|
305
|
-
]
|
306
|
-
}.as_json
|
307
|
-
end
|
308
|
-
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
|
313
|
-
end
|
1
|
+
module T2Airtime
|
2
|
+
class Account
|
3
|
+
def self.get
|
4
|
+
Rails.cache.fetch('accounts', expires_in: 1.hour) do
|
5
|
+
T2Airtime::API.api.account_info
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.currency
|
10
|
+
Rails.cache.fetch('accounts/currency', expires_in: 24.hours) do
|
11
|
+
serialize(get.data)["attributes"]["currency"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.info
|
16
|
+
get.success? ? serialize(get.data, get.headers[:date]) : []
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.serialize(data, ts = Time.zone.now.to_s)
|
20
|
+
{
|
21
|
+
type: 'accounts',
|
22
|
+
id: T2Airtime::API.api.user,
|
23
|
+
attributes: {
|
24
|
+
type: data[:type],
|
25
|
+
name: data[:name],
|
26
|
+
currency: data[:currency],
|
27
|
+
balance: Float(data[:balance]),
|
28
|
+
wallet: Float(data[:wallet]),
|
29
|
+
fetchedAt: T2Airtime::Util.format_time(ts)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Country
|
36
|
+
def self.all
|
37
|
+
Rails.cache.fetch('countries', expires_in: 1.hour) do
|
38
|
+
T2Airtime::API.api.country_list
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.take(qty = 5)
|
43
|
+
countries = all
|
44
|
+
countries.success? ? serialize(countries.data, countries.headers[:date], qty) : []
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.serialize(data, ts = Time.zone.now.to_s, qty = nil)
|
48
|
+
return [] if data[:countryid].nil?
|
49
|
+
names = data[:country].split(',')
|
50
|
+
ids = data[:countryid].split(',')
|
51
|
+
Rails.cache.fetch('countries/serializer', expires_in: 1.hour) do
|
52
|
+
ids.take(qty.nil? ? ids.count : qty).each_with_index.map do |id, n|
|
53
|
+
{
|
54
|
+
type: 'countries',
|
55
|
+
id: Integer(id),
|
56
|
+
attributes: {
|
57
|
+
name: names[n],
|
58
|
+
alpha3: alpha3(names[n]),
|
59
|
+
fetchedAt: T2Airtime::Util.format_time(ts)
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.normalize(name)
|
67
|
+
name.starts_with?('St') ? name.gsub('St', 'Saint') : name
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.alpha3(name)
|
71
|
+
alpha3 = ISO3166::Country.find_country_by_name(name).try(:alpha3)
|
72
|
+
unless alpha3
|
73
|
+
alpha3 = case name
|
74
|
+
when 'Saint Vincent Grenadines'
|
75
|
+
'VCT'
|
76
|
+
when 'Kosovo'
|
77
|
+
'UNK'
|
78
|
+
when 'Netherlands Antilles'
|
79
|
+
'ANT'
|
80
|
+
when 'Serbia and Montenegro'
|
81
|
+
'SCG'
|
82
|
+
end
|
83
|
+
register_alpha3(alpha3, name) if %w[VCT UNK ANT SCG].include?(alpha3)
|
84
|
+
end
|
85
|
+
alpha3 || 'XXX'
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.register_alpha3(alpha3, name)
|
89
|
+
ISO3166::Data.register(
|
90
|
+
alpha2: 'XX',
|
91
|
+
alpha3: alpha3,
|
92
|
+
name: name
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class Operator
|
98
|
+
def self.all(country_id)
|
99
|
+
Rails.cache.fetch("operators/#{country_id}", expires_in: 1.hour) do
|
100
|
+
T2Airtime::API.api.operator_list(country_id)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.take(country_qty = 1, qty = 5)
|
105
|
+
countries = T2Airtime::Country.take(country_qty).shuffle
|
106
|
+
unless countries.empty?
|
107
|
+
countries.flat_map do |country| (
|
108
|
+
operators = all(country['id'])
|
109
|
+
operators.success? ? serialize(operators.data, operators.headers[:date], qty) : []
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.serialize(data, ts = Time.zone.now.to_s, qty = nil)
|
116
|
+
return [] if data[:operator].nil?
|
117
|
+
names = data[:operator].split(',')
|
118
|
+
ids = data[:operatorid].split(',')
|
119
|
+
Rails.cache.fetch("operators/#{data[:countryid]}/serializer", expires_in: 1.hour) do
|
120
|
+
ids.take(qty.nil? ? ids.count : qty).each_with_index.map do |id, n|
|
121
|
+
{
|
122
|
+
type: 'operators',
|
123
|
+
id: Integer(id),
|
124
|
+
attributes: {
|
125
|
+
name: names[n],
|
126
|
+
logo: T2Airtime::Util.operator_logo_url(id),
|
127
|
+
countryId: Integer(data[:countryid]),
|
128
|
+
countryName: data[:country],
|
129
|
+
countryAlpha3: T2Airtime::Country.alpha3(data[:country]),
|
130
|
+
fetchedAt: T2Airtime::Util.format_time(ts)
|
131
|
+
},
|
132
|
+
relationships: {
|
133
|
+
country: {
|
134
|
+
data: {
|
135
|
+
type: 'countries',
|
136
|
+
id: Integer(data[:countryid])
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Product
|
147
|
+
def self.all(operator_id)
|
148
|
+
Rails.cache.fetch("products/#{operator_id}", expires_in: 1.hour) do
|
149
|
+
T2Airtime::API.api.product_list(operator_id)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.take(operator_qty = 1, qty = 5)
|
154
|
+
operators = T2Airtime::Operator.take(operator_qty).shuffle
|
155
|
+
unless operators.empty?
|
156
|
+
operators.flat_map do |operator| (
|
157
|
+
|
158
|
+
|
159
|
+
products = all(operator['id'])
|
160
|
+
products.success? ? serialize(products.data, products.headers[:date], qty) : []
|
161
|
+
)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.serialize(data, ts = Time.zone.now.to_s, qty = nil)
|
167
|
+
return [] if data[:product_list].nil?
|
168
|
+
ids = data[:product_list].split(',')
|
169
|
+
retail_prices = data[:retail_price_list].split(',')
|
170
|
+
wholesale_prices = data[:wholesale_price_list].split(',')
|
171
|
+
Rails.cache.fetch("products/#{data[:operatorid]}/serializer", expires_in: 1.hour) do
|
172
|
+
ids.take(qty.nil? ? ids.count : qty).each_with_index.map do |id, n|
|
173
|
+
{
|
174
|
+
type: 'products',
|
175
|
+
id: Integer(id),
|
176
|
+
attributes: {
|
177
|
+
name: "#{Money.new(Integer(id) * 100, data[:destination_currency]).format}",
|
178
|
+
localCurrency: data[:destination_currency],
|
179
|
+
localCurrencySymbol: Money::Currency.new(data[:destination_currency]).symbol,
|
180
|
+
currency: Account.currency,
|
181
|
+
currencySymbol: Money::Currency.new(Account.currency).symbol,
|
182
|
+
localPrice: Float(id),
|
183
|
+
retailPrice: Float(retail_prices[n]),
|
184
|
+
wholesalePrice: Float(wholesale_prices[n]),
|
185
|
+
countryId: Integer(data[:countryid]),
|
186
|
+
countryName: data[:country],
|
187
|
+
countryAlpha3: T2Airtime::Country.alpha3(data[:country]),
|
188
|
+
operatorId: Integer(data[:operatorid]),
|
189
|
+
operatorName: data[:operator],
|
190
|
+
operatorLogo: T2Airtime::Util.operator_logo_url(data[:operatorid]),
|
191
|
+
fetchedAt: T2Airtime::Util.format_time(ts)
|
192
|
+
},
|
193
|
+
relationships: {
|
194
|
+
country: {
|
195
|
+
data: {
|
196
|
+
type: 'countries',
|
197
|
+
id: Integer(data[:countryid])
|
198
|
+
}
|
199
|
+
},
|
200
|
+
operator: {
|
201
|
+
data: {
|
202
|
+
type: 'operators',
|
203
|
+
id: Integer(data[:operatorid])
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class Transaction
|
214
|
+
def self.take(start = (Time.now - 24.hours), stop = Time.now, msisdn = nil, destination = nil, code = nil, qty = 5)
|
215
|
+
reply = T2Airtime::API.api.transaction_list(start, stop, msisdn, destination, code)
|
216
|
+
reply.success? ? serialize(reply.data, qty) : []
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.serialize(data, qty = nil)
|
220
|
+
return [] if data[:transaction_list].nil?
|
221
|
+
ids = data[:transaction_list].split(',')
|
222
|
+
ids.take(qty.nil? ? ids.count : qty).each.map { |id| show(id) }
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.show(id)
|
226
|
+
reply = T2Airtime::API.api.transaction_info(id)
|
227
|
+
reply.success? ? serialize_one(reply.data, reply.headers[:date]) : {}
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.serialize_one(data, ts = Time.zone.now.to_s)
|
231
|
+
{
|
232
|
+
type: 'transactions',
|
233
|
+
id: Integer(data[:transactionid]),
|
234
|
+
attributes: {
|
235
|
+
msisdn: data[:msisdn],
|
236
|
+
destinationMsisdn: data[:destination_msisdn],
|
237
|
+
transactionAuthenticationKey: data[:transaction_authentication_key],
|
238
|
+
transactionErrorCode: Integer(data[:transaction_error_code]),
|
239
|
+
transactionErrorTxt: data[:transaction_error_txt],
|
240
|
+
referenceOperator: data[:reference_operator],
|
241
|
+
actualProductSent: data[:actual_product_sent],
|
242
|
+
sms: data[:sms],
|
243
|
+
cid1: data[:cid1],
|
244
|
+
cid2: data[:cid2],
|
245
|
+
cid3: data[:cid3],
|
246
|
+
date: data[:date],
|
247
|
+
currency: data[:originating_currency],
|
248
|
+
localCurrency: data[:destination_currency],
|
249
|
+
pinBased: data[:pin_based],
|
250
|
+
localInfoAmount: data[:local_info_amount],
|
251
|
+
localInfoCurrency: data[:local_info_currency],
|
252
|
+
localInfoValue: data[:local_info_value],
|
253
|
+
errorCode: data[:error_code],
|
254
|
+
errorTxt: data[:error_txt],
|
255
|
+
countryId: Integer(data[:countryid]),
|
256
|
+
countryName: data[:country],
|
257
|
+
countryAlpha3: T2Airtime::Country.alpha3(data[:country]),
|
258
|
+
operatorId: Integer(data[:operatorid]),
|
259
|
+
operatorName: data[:operator],
|
260
|
+
operatorLogo: T2Airtime::Util.operator_logo_url(data[:operatorid]),
|
261
|
+
productName: "#{Money.new(Integer(data[:product_requested]) * 100, data[:destination_currency]).format}",
|
262
|
+
productLocalCurrency: data[:destination_currency],
|
263
|
+
productLocalCurrencySymbol: Money::Currency.new(data[:destination_currency]).symbol,
|
264
|
+
productCurrency: Account.currency,
|
265
|
+
productCurrencySymbol: Money::Currency.new(Account.currency).symbol,
|
266
|
+
productLocalPrice: Float(data[:product_requested]),
|
267
|
+
productRetailPrice: Float(data[:retail_price]),
|
268
|
+
productWholesalePrice: Float(data[:wholesale_price]),
|
269
|
+
fetchedAt: T2Airtime::Util.format_time(ts)
|
270
|
+
},
|
271
|
+
relationships: {
|
272
|
+
country: {
|
273
|
+
data: {
|
274
|
+
type: 'countries',
|
275
|
+
id: Integer(data[:countryid])
|
276
|
+
}
|
277
|
+
},
|
278
|
+
operator: {
|
279
|
+
data: {
|
280
|
+
type: 'operators',
|
281
|
+
id: Integer(data[:operatorid])
|
282
|
+
}
|
283
|
+
},
|
284
|
+
product: {
|
285
|
+
data: {
|
286
|
+
type: 'products',
|
287
|
+
id: Integer(data[:product_requested])
|
288
|
+
}
|
289
|
+
}
|
290
|
+
}
|
291
|
+
}
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
data/lib/t2_airtime/url.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
module T2Airtime
|
2
|
-
DOMAIN =
|
3
|
-
AIRTIME_DN =
|
4
|
-
OPLOGO_DN =
|
5
|
-
ENDPOINT =
|
6
|
-
end
|
1
|
+
module T2Airtime
|
2
|
+
DOMAIN = 'transferto.com'.freeze
|
3
|
+
AIRTIME_DN = 'airtime'.freeze
|
4
|
+
OPLOGO_DN = 'operator-logo'.freeze
|
5
|
+
ENDPOINT = 'cgi-bin/shop/topup'.freeze
|
6
|
+
end
|