idtbeyond 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f9a606a8eeaa5218023a248b6b0c97fb6dc5f04
4
+ data.tar.gz: c451d5133b61feff7a9653a270f04c5de0b5c548
5
+ SHA512:
6
+ metadata.gz: 7109388298a1da61a7b057563a9d88aa19f70b71aac1e871883754ebd9a11dc47344ebd2485206c5075df539ed37e9957ca6e025bc1dacfdaf1be885642b8f4e
7
+ data.tar.gz: 598c07ccd5128b98f47f2afc8ad2ecae4f111a6cbefaf33688621eb42da5b4bdd56ec04cc99818810c812654bf5c924e4f371b475de2aab93a61bbb95a42823a
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
@@ -0,0 +1 @@
1
+ idtbeyond
@@ -0,0 +1 @@
1
+ ruby-2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'faraday'
3
+ gem 'json'
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Robbie Holmes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,536 @@
1
+ # Ruby Gem for IDT Beyond
2
+
3
+ [![Join the chat at https://gitter.im/IDTLabs/IDTBeyond-Ruby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/IDTLabs/IDTBeyond-Ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
5
+ The official node package for interacting with the IDT Beyond API.
6
+
7
+ ## Getting started with IDT Beyond
8
+
9
+ To use this service, sign up for a free account at: [https://portal.idtbeyond.com](https://portal.idtbeyond.com), or read the documentation at [https://portal.idtbeyond.com/docs](https://portal.idtbeyond.com/docs).
10
+
11
+ ## Requirements
12
+
13
+ - bundler
14
+ - ruby 2.2.1
15
+
16
+
17
+ ## Setup your environment
18
+
19
+ 1. Make sure above requirements are fulfilled. (see site documentation in links above)
20
+ 2. run `npm install idtbeyond --save` to add this module to your project
21
+
22
+ ## Testing
23
+
24
+ Running `rake spec` will run the unit tests with RSpec 3.x.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/[my-github-username]/idtbeyond/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am "Add some feature"`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
33
+
34
+ ## Usage
35
+
36
+ ```ruby
37
+ require "idtbeyond"
38
+ ```
39
+
40
+ ```ruby
41
+ idtbeyond_iatu = IDTBeyond::Service::IATU.new "app-id", "app-key", "term-id"
42
+ ```
43
+
44
+ <aside class="notice">
45
+ Each application has a unique `app-id` and `app-key`. You can generate up to 5 keys per application, and they can be regenerated by you at any time. Make sure to use the correct ones, and update your code when new valid keys are generated.
46
+ </aside>
47
+
48
+ ####Parameters
49
+
50
+ Parameter | Required | Type | Description
51
+ --------- | ------- | ----- | -----------
52
+ app-id | true | string | Application ID.
53
+ app-key | true | string | Application Key.
54
+ term-id | true | string | Terminal name for the environment serving the application.
55
+
56
+ ## API Status
57
+
58
+ This returns the status of the IDT Beyond API.
59
+
60
+ **Request:**
61
+
62
+ ```ruby
63
+ idtbeyond_iatu.get_status
64
+ ```
65
+
66
+ **Response:**
67
+
68
+ ```json
69
+ {
70
+ "alive":true
71
+ }
72
+ ```
73
+
74
+ ## Get all products
75
+
76
+ This endpoint retrieves a current list of products offered by our IATU API.
77
+
78
+ **Request:**
79
+
80
+ ```ruby
81
+ idtbeyond_iatu.get_products
82
+ ```
83
+
84
+ ```json
85
+ [
86
+ {
87
+ "country":"Guatemala",
88
+ "country_code":"GT",
89
+ "carrier":"Tigo",
90
+ "carrier_code":"Tigo",
91
+ "mask":"502-XXXX-XXXX",
92
+ "denomination":700,
93
+ "minDenomination":700,
94
+ "maxDenomination":700,
95
+ "commission":"10"
96
+ },
97
+ {
98
+ "country":"Argentina",
99
+ "country_code":"AR",
100
+ "carrier":"Movistar",
101
+ "carrier_code":"Movistar",
102
+ "mask":"54-XXXX-XXX-XXXX",
103
+ "denomination":700,
104
+ "minDenomination":700,
105
+ "maxDenomination":700,
106
+ "commission":"14.50"
107
+ }
108
+ ]
109
+ ```
110
+
111
+ ## Local Value
112
+
113
+ Get the local value of a particular product.
114
+
115
+ ### Example:
116
+
117
+ `idtbeyond_iatu.get_local_value amount, "carrier_code", "country_code", "currency_code"`
118
+
119
+ **Request:**
120
+
121
+ ```ruby
122
+ idtbeyond_iatu.get_local_value "500", Claro, "GT", "USD"
123
+ ```
124
+
125
+ **Response:**
126
+
127
+ ```json
128
+ {
129
+ "carrier_code":"Claro",
130
+ "country_code":"GT",
131
+ "amount":"500",
132
+ "currency_code":"USD",
133
+ "local_currency":"GTQ",
134
+ "local_amount":"3965",
135
+ "divisor":"100"
136
+ }
137
+ ```
138
+
139
+ ####Parameters
140
+
141
+ Parameter | Required | Type | Description
142
+ --------- | ------- | ----- | -----------
143
+ country_code | true | string | 2-digit code of the country in ISO 3166 format. Ex: CO for Columbia.
144
+ carrier_code | true | string | Name of the mobile carrier. Ex: Tigo
145
+ currency_code | true | string | The currency code (ISO 4217) on the product you are querying. Ex: USD
146
+ amount | true | integer | The amount of the product you would like to get the value of. Ex: 1000 = $10.00 (in cents).
147
+
148
+
149
+ ## Balance
150
+
151
+ This call allows you get the balance on a specific application.
152
+
153
+ **Request:**
154
+
155
+ ```ruby
156
+ idtbeyond_iatu.get_balance
157
+ ```
158
+
159
+ **Response:**
160
+
161
+ ```json
162
+ {
163
+ "balance":986834,
164
+ "currency_code":"USD",
165
+ "currency_symbol":"$",
166
+ "currency_divisor":100
167
+ }
168
+ ```
169
+
170
+ ## Topup
171
+
172
+ This is how you topup a phone in another country.
173
+
174
+ ### Example:
175
+
176
+ `idtbeyond_iatu.post_topup "amount", "carrier_code", "country_code", "mobile_number"`
177
+
178
+ **Request:**
179
+
180
+ ```ruby
181
+ idtbeyond_iatu.post_topup "1000", "Claro", "GT", "50212345678"
182
+ ```
183
+
184
+ **Response:**
185
+
186
+ ```json
187
+ {
188
+ "success":true,
189
+ "client_transaction_id":"trans_id_12345",
190
+ "transaction_id":"123345678",
191
+ "amount":1000,
192
+ "currency_divisor":"100",
193
+ "currency_symbol":"$",
194
+ "wholesaler_balance":0,
195
+ "wholesaler_commission":100,
196
+ "local_amount":7934,
197
+ "local_currency":"GTQ",
198
+ "local_divisor":"100",
199
+ "plan":"Sandbox",
200
+ "terminal_id":"kiosk 12",
201
+ "carrier_code":"Claro",
202
+ "country_code":"GT",
203
+ "country_name":"Guatemala",
204
+ "mobile_number":1234567890,
205
+ "to_service_number":"0987654321",
206
+ "from_service_number":"9999999999"
207
+ }
208
+ ```
209
+
210
+ <aside class="notice">
211
+ Your `clientTransactionId` is automatically generated by default using the `generateClientTransactionId` function.
212
+ </aside>
213
+
214
+ ####Parameters
215
+
216
+ Parameter | Required | Type | Description
217
+ --------- | ------- | ----- | -----------
218
+ country_code | true | string | 2-digit code of the country in ISO 3166 format. (Ex: **GT** for Guatemala).
219
+ carrier_code | true | string | Name of the mobile carrier. (Ex: **Claro**).
220
+ amount | true | integer | This is the amount, in cents, of the product you are purchasing. (Ex: **500** = $5.00).
221
+ mobile_number | true | integer | Mobile number to topup. VALIDATE prior to submission. (Ex: **50312345678**).
222
+
223
+ ##Topups Reports (all)
224
+
225
+ This will return both the totals report, and the transactions during the dates requested.
226
+
227
+ ### Example:
228
+
229
+ `idtbeyond_iatu.get_all_topups "date_from", "date_to"`
230
+
231
+ **Request:**
232
+
233
+ ```ruby
234
+ idtbeyond_iatu.get_all_topups "2015-01-04", "2015-01-05"
235
+ ```
236
+
237
+ **Response:**
238
+
239
+ ```json
240
+ {
241
+ "success":true,
242
+ "totals":{
243
+ "purchases":"0",
244
+ "transfers":"-500",
245
+ "commissions":"100",
246
+ "transactions_count":"1",
247
+ "actual_last_transaction_date":"2015-01-05T22:44:35",
248
+ "query_start_date":"2015-01-04",
249
+ "query_end_date":"2015-01-05"
250
+ },
251
+ "transactions":[
252
+ {
253
+ "mobile_number":"50212345678",
254
+ "production_pin":"0000000001",
255
+ "client_transaction_id":"Transaction123456",
256
+ "currency_code":"US",
257
+ "currency_symbol":"$",
258
+ "currency_divisor":"100",
259
+ "transaction_date":"2015-01-05T22:44:34",
260
+ "transaction_method":"XFER",
261
+ "transaction_description":"IMTU",
262
+ "transaction_amount":"-500",
263
+ "retail_amount":"-500",
264
+ "retail_commission":"100",
265
+ "account_start_balance":"60575",
266
+ "account_end_balance":"60175",
267
+ "product_name":"IMTU - CLARO UNIVERSAL $5"
268
+ }
269
+ ]
270
+ }
271
+ ```
272
+
273
+ ####Parameters
274
+
275
+ Parameter | Required | Type | Description
276
+ --------- | ------- | ----- | -----------
277
+ date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01).
278
+ date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01).
279
+
280
+ <aside class="success">
281
+ Remember — All date_to and date_from queries are in Eastern Time (ET), by default.
282
+ </aside>
283
+
284
+
285
+ ##Topups Reports (Totals)
286
+
287
+ This returns a summary report of topups totals, within a given time period.
288
+
289
+ ### Example:
290
+
291
+ `idtbeyond_iatu.get_all_topups_totals "date_from", "date_to"`
292
+
293
+ **Request:**
294
+
295
+ ```ruby
296
+ idtbeyond_iatu.get_all_topups_totals "2015-01-01", "2015-01-02"
297
+ ```
298
+
299
+ **Response:**
300
+
301
+ ```json
302
+ {
303
+ "success":true,
304
+ "totals":{
305
+ "from_service_number":"133333333",
306
+ "sales":"50000",
307
+ "cost":"40000",
308
+ "commissions":"10000",
309
+ "transactions_count":"100",
310
+ "actual_last_transaction_date":"2015-01-02T23:59:59",
311
+ "query_start_date":"2015-01-01",
312
+ "query_end_date":"2015-01-02",
313
+ "currency_code":"US",
314
+ "currency_symbol":"$",
315
+ "currency_divisor":"100"
316
+ }
317
+ }
318
+ ```
319
+
320
+ ####Parameters
321
+
322
+ Parameter | Required | Type | Description
323
+ --------- | ------- | ----- | -----------
324
+ date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01).
325
+ date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01).
326
+
327
+ <aside class="success">
328
+ Remember — All date_to and date_from queries are in Eastern Time (ET), by default.
329
+ </aside>
330
+
331
+ ##Topups Reports (Search)
332
+
333
+ Search for transaction details using your **client_transaction_id**.
334
+
335
+ ### Example:
336
+
337
+ `idtbeyond_iatu.client_transaction_id_search "client_transaction_id", "date_from", "date_to"`
338
+
339
+ **Request:**
340
+
341
+ ```ruby
342
+ idtbeyond_iatu.client_transaction_id_search "my-client-trans-id", "2015-03-01", "2015-03-11"
343
+ ```
344
+
345
+ **Response:**
346
+
347
+ ```json
348
+ {
349
+ "success":true,
350
+ "transaction_data":[
351
+ {
352
+ "currency_code":"USD",
353
+ "currency_symbol":"$",
354
+ "currency_divisor":"100",
355
+ "client_transaction_id":"my-client-trans-id",
356
+ "transaction_date":"3/1/2015 10:57:04 AM",
357
+ "description":"Success",
358
+ "commission":"100",
359
+ "type":"IMTU - CLARO UNIVERSAL $5",
360
+ "end_balance":"56915",
361
+ "amount":"-500",
362
+ "terminal_id":"testTerminalId",
363
+ "transaction_status":"Success",
364
+ "to_service_number":"117123456"
365
+ }
366
+ ]
367
+ }
368
+ ```
369
+
370
+ ####Parameters
371
+
372
+ Parameter | Required | Type | Description
373
+ --------- | ------- | ----- | -----------
374
+ date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: **2015-12-01**).
375
+ date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: **2015-12-01**).
376
+ client_transaction_id | true | string | A unique id you use to track topups (Limit of 20 characters).
377
+
378
+ <aside class="success">
379
+ Remember — All date_to and date_from queries are in Eastern Time (ET), by default.
380
+ </aside>
381
+
382
+
383
+ ##Topups Reports (Quick Status)
384
+
385
+ When you submit a transaction, we do some very detailed handling to complete the request. The **to_service_number** is a tracking method used to follow the status of this request, including the balance of the transaction handoff to the carrier. Use this endpoint to get a quick update on the status of the request.
386
+
387
+ ### Example:
388
+
389
+ `idtbeyond_iatu.to_service_number_search "to_service_number"`
390
+
391
+ **Request:**
392
+
393
+ ```ruby
394
+ idtbeyond_iatu.to_service_number_search "2712345678"
395
+ ```
396
+
397
+ **Response:**
398
+
399
+ ```json
400
+ {
401
+ "success": true,
402
+ "transaction_data": {
403
+ "balance": "0",
404
+ "status": "Redeemed"
405
+ }
406
+ }
407
+ ```
408
+
409
+ ####Parameters
410
+
411
+ Parameter | Required | Type | Description
412
+ --------- | ------- | ----- | -----------
413
+ to_service_number | true | string | A unique IDT transaction number that gives the status of the transfer of funds from your account to the carrier.
414
+
415
+
416
+ ##Topups (Reverse)
417
+
418
+ Use this method to search for the status of a particular topup transaction, using the unique **clientTransactionId** you supplied in the request, and use the **toServiceNumber**.
419
+
420
+ Occasionally, a carrier will not be able to successfully complete a topup request. In this case, we will attempt to automatically reverse the transaction for you, and return the money into your account. In the case when this is not possible, you may need to request a reverse on the transaction that has a status of **"status": "Not Redeemed"**.
421
+
422
+ ### Example:
423
+
424
+ `idtbeyond_iatu.reverse_topup "client_transaction_id", "to_service_number"`
425
+
426
+ **Request:**
427
+
428
+ ```ruby
429
+ idtbeyond_iatu.reverse_topup "my-client-trans-id", "2712345678"
430
+ ```
431
+
432
+ **Response:**
433
+
434
+ ```json
435
+ {
436
+ "success":true,
437
+ "account_id":"12345678",
438
+ "client_transaction_id":"my-client-trans-id",
439
+ "transaction_id":"111222333",
440
+ "to_service_number":"2712345678",
441
+ "remaining_amount":0,
442
+ "currency_symbol":"$",
443
+ "currency_divisor":"100"
444
+ }
445
+ ```
446
+
447
+
448
+ ####Parameters
449
+
450
+ Parameter | Required | Type | Description
451
+ --------- | ------- | ----- | -----------
452
+ client_transaction_id | true | string | A unique id you use to track topups (Limit of 16 characters).
453
+ to_service_number | true | string | The service number of the financial transaction (moving the money between your balance and the carrier).
454
+
455
+ ## Charges Reports (all)
456
+
457
+ Returns a list of any credit card charges, wire-transfers, or credit adjustments on your application account.
458
+ **Request:**
459
+
460
+ ```ruby
461
+ idtbeyond_iatu.get_all_charges "2015-03-01", "2015-03-11"
462
+ ```
463
+
464
+ **Response:**
465
+
466
+ ```json
467
+ {
468
+ "success":true,
469
+ "totals":{
470
+ "purchases":"0",
471
+ "transfers":"0",
472
+ "commissions":"0",
473
+ "transactions_count":"1",
474
+ "actual_last_transaction_date":"2015-03-02T20:04:45",
475
+ "query_start_date":"2015-03-01",
476
+ "query_end_date":"2015-03-11"
477
+ },
478
+ "transactions":[
479
+ {
480
+ "mobile_number":"",
481
+ "production_pin":"",
482
+ "client_transaction_id":"12345678",
483
+ "currency_code":"US",
484
+ "currency_symbol":"$",
485
+ "currency_divisor":"100",
486
+ "transaction_date":"2015-03-02T20:04:44",
487
+ "transaction_method":"CREDIT_LOAD",
488
+ "transaction_description":"Credit Load",
489
+ "transaction_amount":"100000",
490
+ "retail_commission":"0",
491
+ "account_start_balance":"0",
492
+ "account_end_balance":"100000",
493
+ "product_name":"CREDIT_LOAD"
494
+ }
495
+ ]
496
+ }
497
+ ```
498
+
499
+
500
+ ####Parameters
501
+
502
+ Parameter | Required | Type | Description
503
+ --------- | ------- | ----- | -----------
504
+ date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01).
505
+ date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01).
506
+
507
+ <aside class="success">
508
+ Remember — All date_to and date_from queries are in Eastern Time (ET), by default.
509
+ </aside>
510
+
511
+ ##Number Validator
512
+
513
+ This method validates that a phone number has a valid area code and number of digits for the selected country.
514
+
515
+ **Request:**
516
+
517
+ ```ruby
518
+ idtbeyond_iatu.validate_number "GT", "50212345678"
519
+ ```
520
+
521
+ **Response:**
522
+
523
+ ```json
524
+ {
525
+ "country_code":"GT",
526
+ "mobile_number":"50212345678",
527
+ "valid":true
528
+ }
529
+ ```
530
+
531
+ ####Parameters
532
+
533
+ Parameter | Required | Type | Description
534
+ --------- | ------- | ----- | -----------
535
+ country_code | true | string | 2-digit code of the country in ISO 3166 format. (Ex: **BR** for Brazil).
536
+ mobile_number | true | string | Mobile number to topup. VALIDATE prior to submission. (Ex: **5521983339000**).
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+
5
+ # Default directory to look in is `/specs`
6
+ # Run with `rake spec`
7
+ RSpec::Core::RakeTask.new('spec')
8
+
9
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'idtbeyond/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "idtbeyond"
8
+ spec.version = IDTBeyond::VERSION
9
+ spec.authors = ["Robbie Holmes"]
10
+ spec.email = ["robbiethegeek@gmail.com"]
11
+ spec.summary = %q{The gem for interacting with the IDTBeyond API.}
12
+ spec.description = %q{This gem will allow developers to interact with the IDTBeyond API for all published services.}
13
+ spec.homepage = "https://github.com/IDTLabs/IDTBeyond-Ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "idtbeyond/version"
2
+ require "idtbeyond/services/imtu"
3
+
4
+ module IDTBeyond
5
+
6
+ end
@@ -0,0 +1,114 @@
1
+ require "faraday"
2
+ require "json"
3
+
4
+ module IDTBeyond
5
+ class Service
6
+ class IATU
7
+ # Constructor
8
+ def initialize(app_id = nil, app_key = nil, term_id = nil)
9
+ raise "app_id, app_key and term_id are required" if app_key.nil? || app_id.nil? || term_id.nil?
10
+ @app_id = app_id
11
+ @app_key = app_key
12
+ @term_id = term_id
13
+ @url = ENV["IDTBEYOND_API_URL"] || "https://api.idtbeyond.com"
14
+ @plan_type = ENV["IDTBEYOND_PLAN_TYPE"] || "Production"
15
+ @conn = Faraday.new(:url => @url, :headers => {
16
+ "x-idt-beyond-app-id" => @app_id,
17
+ "x-idt-beyond-app-key" => @app_key
18
+ }) do |faraday|
19
+ faraday.request :url_encoded
20
+ faraday.response :logger
21
+ faraday.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+
25
+ # API Methods
26
+
27
+ def client_transaction_id_search(client_transaction_id, date_from, date_to)
28
+ response = @conn.post "/v1/iatu/topups/reports", {
29
+ :client_transaction_id => client_transaction_id,
30
+ :type_of_report => "client_transaction_id",
31
+ :date_from => date_from,
32
+ :date_to => date_to
33
+ }
34
+ JSON response.body
35
+ end
36
+ def get_all_charges(date_from, date_to)
37
+ response = @conn.get "/v1/iatu/charges/reports/all", {:date_from => date_from, :date_to => date_to}
38
+ return JSON response.body if response.status == 200
39
+ false
40
+ end
41
+ def get_all_topups(date_from, date_to)
42
+ response = @conn.get "/v1/iatu/topups/reports/all", {:date_from => date_from, :date_to => date_to}
43
+ return JSON response.body if response.status == 200
44
+ false
45
+ end
46
+ def get_all_topups_totals(date_from, date_to)
47
+ response = @conn.get "/v1/iatu/topups/reports/totals", {:date_from => date_from, :date_to => date_to}
48
+ return JSON response.body if response.status == 200
49
+ false
50
+ end
51
+ def get_app_id
52
+ @app_id
53
+ end
54
+
55
+ def get_app_key
56
+ @app_key
57
+ end
58
+ def get_balance
59
+ response = @conn.get "/v1/iatu/balance"
60
+ return JSON response.body if response.status == 200
61
+ false
62
+ end
63
+ def get_local_value(amount, carrier_code, country_code, currency_code)
64
+ response = @conn.get "/v1/iatu/products/reports/local-value", {
65
+ :carrier_code => carrier_code,
66
+ :country_code => country_code,
67
+ :currency_code => currency_code,
68
+ :amount => amount
69
+ }
70
+ JSON response.body
71
+ end
72
+
73
+ def get_status
74
+ response = @conn.get "/v1/status"
75
+ p response
76
+ return JSON response.body if response.status == 200
77
+ false
78
+ end
79
+
80
+ def post_topup(amount, carrier_code, country_code, mobile_number )
81
+ client_transaction_id = @app_id + "-" + "%06d" % Random.rand(0..999999)
82
+ response = @conn.post "/v1/iatu/topups", {
83
+ :country_code => country_code,
84
+ :carrier_code => carrier_code,
85
+ :client_transaction_id => client_transaction_id,
86
+ :terminal_id => @term_id,
87
+ :mobile_number => mobile_number,
88
+ :plan => @plan_type,
89
+ :amount => amount
90
+ }
91
+ JSON response.body
92
+ end
93
+ def reverse_topup(client_transaction_id, to_service_number)
94
+ response = @conn.post "/v1/iatu/topups/reverse", {
95
+ :client_transaction_id => client_transaction_id,
96
+ :to_service_number => to_service_number
97
+ }
98
+ JSON response.body
99
+ end
100
+ def to_service_number_search(to_service_number)
101
+ response = @conn.post "/v1/iatu/topups/reports", {
102
+ :to_service_number => to_service_number,
103
+ :type_of_report => "to_service_number"
104
+ }
105
+ JSON response.body
106
+ end
107
+ def validate_number(country_code, mobile_number)
108
+ response = @conn.get "/v1/iatu/number-validator", {
109
+ :country_code => country_code, :mobile_number => mobile_number}
110
+ JSON response.body
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,3 @@
1
+ module IDTBeyond
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,218 @@
1
+ require "spec_helper"
2
+ require "webmock"
3
+ describe "IDTBeyond - IMTU" do
4
+ before(:each) do
5
+ @idtbeyond = IDTBeyond::Service::IATU.new "app-id", "app-key", "test term id"
6
+
7
+ end
8
+ describe "client_transaction_id_search" do
9
+ it "should call the /v1/iatu/topups/reports" do
10
+ stub_request(:post, "https://api.idtbeyond.com/v1/iatu/topups/reports").
11
+ with(
12
+ :body => {
13
+ "client_transaction_id"=>"client-transaction-id",
14
+ "date_from" => "date-from",
15
+ "date_to" => "date-to",
16
+ "type_of_report"=>"client_transaction_id" },
17
+ :headers => {
18
+ "Accept"=>"*/*",
19
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
20
+ "Content-Type"=>"application/x-www-form-urlencoded",
21
+ "User-Agent"=>"Faraday v0.9.1",
22
+ "X-Idt-Beyond-App-Id"=>"app-id",
23
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
24
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
25
+ response = @idtbeyond.client_transaction_id_search("client-transaction-id", "date-from", "date-to")
26
+ expect(response["success"]).to eq(true)
27
+ end
28
+ end
29
+ describe "get_all_charges" do
30
+ it "should call the /v1/iatu/charges/reports/all" do
31
+ stub_request(
32
+ :get,
33
+ "https://api.idtbeyond.com/v1/iatu/charges/reports/all?date_from=date-from&date_to=date-to").
34
+ with(
35
+ :headers => {
36
+ "Accept"=>"*/*",
37
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
38
+ "User-Agent"=>"Faraday v0.9.1",
39
+ "X-Idt-Beyond-App-Id"=>"app-id",
40
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
41
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
42
+
43
+ response = @idtbeyond.get_all_charges("date-from", "date-to")
44
+ expect(response["success"]).to eq(true)
45
+ end
46
+ end
47
+ describe "get_all_topups" do
48
+ it "should call the /v1/iatu/topups/reports/all" do
49
+ stub_request(
50
+ :get,
51
+ "https://api.idtbeyond.com/v1/iatu/topups/reports/all?date_from=date-from&date_to=date-to").
52
+ with(
53
+ :headers => {
54
+ "Accept"=>"*/*",
55
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
56
+ "User-Agent"=>"Faraday v0.9.1",
57
+ "X-Idt-Beyond-App-Id"=>"app-id",
58
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
59
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
60
+ response = @idtbeyond.get_all_topups("date-from", "date-to")
61
+ expect(response["success"]).to eq(true)
62
+ end
63
+ end
64
+ describe "get_all_topups_totals" do
65
+ it "should call the /v1/iatu/topups/reports/totals" do
66
+ stub_request(
67
+ :get,
68
+ "https://api.idtbeyond.com/v1/iatu/topups/reports/totals?date_from=date-from&date_to=date-to").
69
+ with(
70
+ :headers => {
71
+ "Accept"=>"*/*",
72
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
73
+ "User-Agent"=>"Faraday v0.9.1",
74
+ "X-Idt-Beyond-App-Id"=>"app-id",
75
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
76
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
77
+
78
+ response = @idtbeyond.get_all_topups_totals("date-from", "date-to")
79
+ expect(response["success"]).to eq(true)
80
+ end
81
+ end
82
+ describe "get_app_id" do
83
+ it "returns the app id that was passed in during instantiation " do
84
+ expect(@idtbeyond.get_app_id).to eq("app-id")
85
+ end
86
+ end
87
+ describe "get_app_key" do
88
+ it "returns the app key that was passed in during instantiation " do
89
+ expect(@idtbeyond.get_app_key).to eq("app-key")
90
+ end
91
+ end
92
+ describe "get_balance" do
93
+ it "should call the /v1/iatu/balance" do
94
+ stub_request(:get, "https://api.idtbeyond.com/v1/iatu/balance").
95
+ with(
96
+ :headers => {
97
+ "Accept"=>"*/*",
98
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
99
+ "User-Agent"=>"Faraday v0.9.1",
100
+ "X-Idt-Beyond-App-Id"=>"app-id",
101
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
102
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
103
+
104
+ response = @idtbeyond.get_balance
105
+ expect(response["success"]).to eq(true)
106
+ end
107
+ end
108
+ describe "get_local_value" do
109
+ it "should call the /v1/iatu/number-validator" do
110
+ stub_request(
111
+ :get,
112
+ "https://api.idtbeyond.com/v1/iatu/products/reports/local-value?amount=amount&carrier_code=carrier-code&country_code=country-code&currency_code=currency-code").
113
+ with(
114
+ :headers => {
115
+ "Accept"=>"*/*",
116
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
117
+ "User-Agent"=>"Faraday v0.9.1",
118
+ "X-Idt-Beyond-App-Id"=>"app-id",
119
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
120
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
121
+ response = @idtbeyond.get_local_value("amount", "carrier-code", "country-code", "currency-code")
122
+ expect(response["success"]).to eq(true)
123
+ end
124
+ end
125
+ describe "get_status" do
126
+ it "should call the /v1/status" do
127
+ stub_request(:get, "https://api.idtbeyond.com/v1/status").
128
+ with(:headers => {
129
+ "Accept"=>"*/*",
130
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
131
+ "User-Agent"=>"Faraday v0.9.1",
132
+ "X-Idt-Beyond-App-Id"=>"app-id",
133
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
134
+ to_return(:status => 200, :body => "{\"alive\":true}", :headers => {})
135
+ response = @idtbeyond.get_status
136
+ expect(response["alive"]).to eq(true)
137
+ end
138
+ end
139
+ describe "post_topup" do
140
+ it "should call the /v1/iatu/topups" do
141
+ stub_request(:post, "https://api.idtbeyond.com/v1/iatu/topups").
142
+ with(
143
+ :body => {
144
+ "amount"=>"amount",
145
+ "carrier_code"=>"carrier-code",
146
+ "client_transaction_id"=>/app-id-\d+/,
147
+ "country_code"=>"country-code",
148
+ "mobile_number"=>"phone-number",
149
+ "plan"=>"Production",
150
+ "terminal_id"=>"test term id"},
151
+ :headers => {
152
+ "Accept"=>"*/*",
153
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
154
+ "Content-Type"=>"application/x-www-form-urlencoded",
155
+ "User-Agent"=>"Faraday v0.9.1",
156
+ "X-Idt-Beyond-App-Id"=>"app-id",
157
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
158
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
159
+ response = @idtbeyond.post_topup "amount", "carrier-code", "country-code", "phone-number"
160
+ expect(response["success"]).to eq(true)
161
+ end
162
+ end
163
+ describe "reverse_topup" do
164
+ it "should call the /v1/iatu/topups/reverse" do
165
+ stub_request(:post, "https://api.idtbeyond.com/v1/iatu/topups/reverse").
166
+ with(
167
+ :body => {
168
+ "client_transaction_id"=>"client-transaction-id",
169
+ "to_service_number"=>"to-service-number"},
170
+ :headers => {
171
+ "Accept"=>"*/*",
172
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
173
+ "Content-Type"=>"application/x-www-form-urlencoded",
174
+ "User-Agent"=>"Faraday v0.9.1",
175
+ "X-Idt-Beyond-App-Id"=>"app-id",
176
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
177
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
178
+ response = @idtbeyond.reverse_topup "client-transaction-id", "to-service-number"
179
+ expect(response["success"]).to eq(true)
180
+ end
181
+ end
182
+ describe "to_service_number_search" do
183
+ it "should call the /v1/iatu/topups/reports" do
184
+ stub_request(:post, "https://api.idtbeyond.com/v1/iatu/topups/reports").
185
+ with(
186
+ :body => {
187
+ "to_service_number"=>"to-service-number",
188
+ "type_of_report"=>"to_service_number" },
189
+ :headers => {
190
+ "Accept"=>"*/*",
191
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
192
+ "Content-Type"=>"application/x-www-form-urlencoded",
193
+ "User-Agent"=>"Faraday v0.9.1",
194
+ "X-Idt-Beyond-App-Id"=>"app-id",
195
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
196
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
197
+ response = @idtbeyond.to_service_number_search("to-service-number")
198
+ expect(response["success"]).to eq(true)
199
+ end
200
+ end
201
+ describe "validate_number" do
202
+ it "should call the /v1/iatu/number-validator" do
203
+ stub_request(
204
+ :get,
205
+ "https://api.idtbeyond.com/v1/iatu/number-validator?country_code=country-code&mobile_number=phone-number").
206
+ with(
207
+ :headers => {
208
+ "Accept"=>"*/*",
209
+ "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
210
+ "User-Agent"=>"Faraday v0.9.1",
211
+ "X-Idt-Beyond-App-Id"=>"app-id",
212
+ "X-Idt-Beyond-App-Key"=>"app-key"}).
213
+ to_return(:status => 200, :body => "{\"success\":true}", :headers => {})
214
+ response = @idtbeyond.validate_number("country-code", "phone-number")
215
+ expect(response["success"]).to eq(true)
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,8 @@
1
+ require 'pry'
2
+ require 'idtbeyond'
3
+ require 'idtbeyond/services/imtu'
4
+ require 'webmock/rspec'
5
+ require 'webmock/rspec/matchers'
6
+ require 'webmock/rspec/matchers/request_pattern_matcher'
7
+ require 'webmock/rspec/matchers/webmock_matcher'
8
+ WebMock.disable_net_connect!(allow_localhost: true)
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: idtbeyond
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robbie Holmes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem will allow developers to interact with the IDTBeyond API for
84
+ all published services.
85
+ email:
86
+ - robbiethegeek@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".ruby-gemset"
93
+ - ".ruby-version"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - idtbeyond.gemspec
99
+ - lib/idtbeyond.rb
100
+ - lib/idtbeyond/services/imtu.rb
101
+ - lib/idtbeyond/version.rb
102
+ - spec/imtu_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/IDTLabs/IDTBeyond-Ruby
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: The gem for interacting with the IDTBeyond API.
128
+ test_files:
129
+ - spec/imtu_spec.rb
130
+ - spec/spec_helper.rb