t2_airtime 0.1.3 → 0.1.5

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
  SHA1:
3
- metadata.gz: 4f76c758dc19f0a18801723bce129f79b3901ef2
4
- data.tar.gz: 939e2277d01c62ef4d24ca7f772305352e0569c5
3
+ metadata.gz: e8417b02b8f2234aeb4bd95b977e84d41a1aa7f3
4
+ data.tar.gz: a9ad3262412847aa81343d5cd1a027e165657515
5
5
  SHA512:
6
- metadata.gz: 7d734a1bd8ac1b49d86311205f4d4be15b0c3728de5132a440f6816010f529ef413cabf0dbfec74fb07adfd4effd8908cf568234499fe36e7820b43394f17d9f
7
- data.tar.gz: 2f0f8aa5be119dda169c520b01c54cea00804c452f0d612c53f28fdffb90d280c330cd908984960149e633e3d6aefb69772af8970e1cbb244366302529169710
6
+ metadata.gz: 377d4ad5ea8676514dcf8e9e4024b76fd5a53e5ca6ec7c5b7f492caebc7052733e2cf511af3fad0661ce9936cb936b1c084b6c2ece6eb884cea650e7210f5610
7
+ data.tar.gz: 3f4ff3db7be4902a83e7e7e77dd90e365be2c370e1e5ef028f85219887583d034f6576c7cdeb23c0331d498466c134c4c26986db4633b2aa9c5b193b2bb70380
@@ -252,11 +252,6 @@ module T2Airtime
252
252
  # @operator_aid the airtime id of the operator
253
253
  def product_list(operator_aid) price_list('operator', operator_aid) end
254
254
 
255
- # Operator Logo URL
256
- def operator_logo_url(operator_aid, size=1)
257
- "#{T2Airtime::PROTOCOL}://#{T2Airtime::OPLOGO_DN}.#{T2Airtime::DOMAIN}/logo-#{operator_aid}-#{size}.png"
258
- end
259
-
260
255
  private
261
256
 
262
257
  def oid=(operator_aid)
@@ -26,21 +26,13 @@ module T2Airtime
26
26
  add_param :login, @user
27
27
  end
28
28
 
29
- def add_param(key, value)
30
- @params[key.to_sym] = value
31
- end
29
+ def add_param(key, value) @params[key.to_sym] = value end
32
30
 
33
- def key
34
- @params[:key]
35
- end
31
+ def key() @params[:key] end
36
32
 
37
- def get?
38
- @params[:method] == :get
39
- end
33
+ def get?() @params[:method] == :get end
40
34
 
41
- def post?
42
- @params[:method] == :post
43
- end
35
+ def post?() @params[:method] == :post end
44
36
 
45
37
  # More than 99.5% of the transactions are currently processed within a few seconds.
46
38
  # However, it may happen in some rare cases that a transaction takes longer to be processed by the receiving
@@ -0,0 +1,201 @@
1
+ module T2Airtime
2
+
3
+ class Account
4
+
5
+ def self.info
6
+ reply = T2Airtime::API.api.check_wallet
7
+ reply.success? ? serialize(reply.data) : {}
8
+ end
9
+
10
+ def self.serialize(data)
11
+ {
12
+ type: data[:type],
13
+ name: data[:name],
14
+ currency: data[:currency],
15
+ balance: Float(data[:balance]),
16
+ wallet: Float(data[:wallet]),
17
+ balance_display: T2Airtime::Util.format_price(data[:balance], data[:currency]),
18
+ wallet_display: T2Airtime::Util.format_price(data[:wallet], data[:currency]),
19
+ }
20
+ end
21
+
22
+ end
23
+
24
+ class Country
25
+
26
+ def self.take(qty=5)
27
+ reply = T2Airtime::API.api.country_list
28
+ reply.success? ? serialize(reply.data, qty) : []
29
+ end
30
+
31
+ def self.serialize(data, qty=nil)
32
+ names = data[:country].split(",")
33
+ ids = data[:countryid].split(",")
34
+ ids.take(qty.nil? ? ids.count : qty).each_with_index.map{|id, n| {
35
+ name: names[n],
36
+ alpha3: alpha3(names[n]),
37
+ aid: Integer(id)
38
+ }}
39
+ end
40
+
41
+ def self.normalize(name)
42
+ name.starts_with?("St") ? name.gsub("St", "Saint") : name
43
+ end
44
+
45
+ def self.alpha3(name)
46
+ alpha3 = ISO3166::Country.find_country_by_name(name).try(:alpha3)
47
+ unless alpha3
48
+ alpha3 = case name
49
+ when 'Saint Vincent Grenadines'
50
+ 'VCT';
51
+ when 'Kosovo'
52
+ 'UNK'
53
+ when 'Netherlands Antilles'
54
+ 'ANT'
55
+ when 'Serbia and Montenegro'
56
+ 'SCG'
57
+ end
58
+ register_alpha3(alpha3, name) if %w(VCT UNK ANT SCG).include?(alpha3)
59
+ end
60
+ alpha3 || "XXX"
61
+ end
62
+
63
+ def self.register_alpha3(alpha3, name)
64
+ ISO3166::Data.register(
65
+ alpha2: 'XX',
66
+ alpha3: alpha3,
67
+ name: name
68
+ )
69
+ end
70
+
71
+ end
72
+
73
+ class Operator
74
+
75
+ def self.take(country_qty=1, qty=5)
76
+ countries = T2Airtime::Country.take(country_qty).shuffle
77
+ unless countries.empty?
78
+ countries.flat_map{|country| (
79
+ reply = T2Airtime::API.api.operator_list(country[:aid])
80
+ reply.success? ? serialize(reply.data, qty) : []
81
+ )}
82
+ end
83
+ end
84
+
85
+ def self.serialize(data, qty=nil)
86
+ names = data[:operator].split(",")
87
+ ids = data[:operatorid].split(",")
88
+ ids.take(qty.nil? ? ids.count : qty).each_with_index.map{|id, n| {
89
+ country: data[:country],
90
+ country_aid: Integer(data[:countryid]),
91
+ alpha3: T2Airtime::Country.alpha3(data[:country]),
92
+ name: names[n],
93
+ logo_url: T2Airtime::Util.operator_logo_url(id),
94
+ aid: Integer(id)
95
+ }}
96
+ end
97
+
98
+ end
99
+
100
+ class Product
101
+
102
+ def self.take(operator_qty=1, qty=5)
103
+ operators = T2Airtime::Operator.take(operator_qty).shuffle
104
+ unless operators.empty?
105
+ operators.flat_map{|operator| (
106
+ reply = T2Airtime::API.api.product_list(operator[:aid])
107
+ reply.success? ? serialize(reply.data, qty) : []
108
+ )}
109
+ end
110
+ end
111
+
112
+ def self.serialize(data, qty=nil)
113
+ currency = data[:destination_currency]
114
+ retail_prices = data[:retail_price_list].split(",")
115
+ wholesale_prices = data[:wholesale_price_list].split(",")
116
+ ids = data[:product_list].split(",")
117
+ ids.take(qty.nil? ? ids.count : qty).each_with_index.map{|id, n| {
118
+ country: data[:country],
119
+ country_aid: Integer(data[:countryid]),
120
+ alpha3: T2Airtime::Country.alpha3(data[:country]),
121
+ operator: data[:operator],
122
+ operator_aid: Integer(data[:operatorid]),
123
+ operator_logo_url: T2Airtime::Util.operator_logo_url(data[:operatorid]),
124
+ name: "#{id}#{currency}",
125
+ currency: currency,
126
+ local_price: Float(id),
127
+ retail_price: Float(retail_prices[n]),
128
+ wholesale_price: Float(wholesale_prices[n]),
129
+ local_price_display: T2Airtime::Util.format_price(id, currency),
130
+ retail_price_display: T2Airtime::Util.format_price(retail_prices[n]),
131
+ wholesale_price_display: T2Airtime::Util.format_price(wholesale_prices[n]),
132
+ aid: Integer(id)
133
+ }}
134
+ end
135
+
136
+ end
137
+
138
+ class Transaction
139
+
140
+ def self.take(start=(Time.now-24.hours), stop=Time.now, msisdn=nil, destination=nil, code=nil, qty=5)
141
+ reply = T2Airtime::API.api.trans_list(start, stop, msisdn, destination, code)
142
+ reply.success? ? serialize(reply.data, qty) : []
143
+ end
144
+
145
+ def self.serialize(data, qty=nil)
146
+ ids = data[:transaction_list].split(",")
147
+ ids.empty? ? {} : ids.take(qty.nil? ? ids.count : qty).each.map{ |id| show(id) }
148
+ end
149
+
150
+
151
+ def self.show(id)
152
+ reply = T2Airtime::API.api.trans_info(id)
153
+ reply.success? ? serialize_one(reply.data) : {}
154
+ end
155
+
156
+ def self.serialize_one(t)
157
+ {
158
+ id: Integer(t[:transactionid]),
159
+ msisdn: t[:msisdn],
160
+ destination_msisdn: t[:destination_msisdn],
161
+ transaction_authentication_key: t[:transaction_authentication_key],
162
+ transaction_error_code: Integer(t[:transaction_error_code]),
163
+ transaction_error_txt: t[:transaction_error_txt],
164
+ country: t[:country],
165
+ country_aid: Integer(t[:countryid]),
166
+ alpha3: T2Airtime::Country.alpha3(t[:country]),
167
+ operator: t[:operator],
168
+ operator_aid: Integer(t[:operatorid]),
169
+ operator_logo_url: T2Airtime::Util.operator_logo_url(t[:operatorid]),
170
+ reference_operator: t[:reference_operator],
171
+ product_requested: t[:product_requested],
172
+ product_requested_display: T2Airtime::Util.format_price(t[:product_requested], t[:destination_currency]),
173
+ actual_product_sent: t[:actual_product_sent],
174
+ actual_product_sent_display: T2Airtime::Util.format_price(t[:actual_product_sent], t[:destination_currency]),
175
+ wholesale_price: t[:wholesale_price],
176
+ wholesale_price_display: T2Airtime::Util.format_price(t[:wholesale_price], t[:originating_currency]),
177
+ retail_price: t[:retail_price],
178
+ retail_price_display: T2Airtime::Util.format_price(t[:retail_price], t[:originating_currency]),
179
+ sms: t[:sms],
180
+ cid1: t[:cid1],
181
+ cid2: t[:cid2],
182
+ cid3: t[:cid3],
183
+ date: t[:date],
184
+ originating_currency: t[:originating_currency],
185
+ destination_currency: t[:destination_currency],
186
+ pin_based: t[:pin_based],
187
+ local_info_amount: t[:local_info_amount],
188
+ local_info_amount_display: T2Airtime::Util.format_price(t[:local_info_amount], t[:local_info_currency]),
189
+ local_info_currency: t[:local_info_currency],
190
+ local_info_value: t[:local_info_value],
191
+ local_info_value_display: T2Airtime::Util.format_price(t[:local_info_value], t[:local_info_currency]),
192
+ error_code: t[:error_code],
193
+ error_txt: t[:error_txt]
194
+ }
195
+ end
196
+
197
+
198
+ end
199
+
200
+
201
+ end
@@ -1,5 +1,5 @@
1
1
  module T2Airtime
2
- class Test
2
+ class Util
3
3
 
4
4
  # A few fake phone numbers in Indonesia have been created and set up with available products of IDR 5000, 10000, 20000, 50000 and 100000:
5
5
  # 628123456710: error code 0 for PIN based Top-up (successful transaction).
@@ -10,12 +10,21 @@ module T2Airtime
10
10
  # 628123456798: error code 998 (system not available, please retry later).
11
11
  # 628123456799: error code 999 (unknown error, please contact support).
12
12
 
13
- def self.numbers(num=0)
13
+ def self.test_numbers(num=0)
14
14
  numbers = [ "628123456710", "628123456770", "628123456780",
15
15
  "628123456781", "628123456790", "628123456798",
16
16
  "628123456799" ]
17
17
  num > 0 && num < 8 ? numbers[num-1] : numbers
18
18
  end
19
19
 
20
+ def self.format_price(price, currency=ENV['T2_CURRENCY'])
21
+ Money.new(Float(price)*100, currency).format
22
+ end
23
+
24
+ # Operator Logo URL
25
+ def self.operator_logo_url(operator_aid, size=1)
26
+ "https://#{T2Airtime::OPLOGO_DN}.#{T2Airtime::DOMAIN}/logo-#{operator_aid}-#{size}.png"
27
+ end
28
+
20
29
  end
21
30
  end
@@ -1,3 +1,3 @@
1
1
  module T2Airtime
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/t2_airtime.rb CHANGED
@@ -2,6 +2,8 @@ require 'dotenv'
2
2
  Dotenv.load
3
3
  require "faraday"
4
4
  require "net/http"
5
+ require "countries"
6
+ require "money"
5
7
 
6
8
  require "t2_airtime/version"
7
9
  require "t2_airtime/url"
@@ -10,7 +12,7 @@ require "t2_airtime/request"
10
12
  require "t2_airtime/reply"
11
13
  require "t2_airtime/base"
12
14
  require "t2_airtime/api"
13
- require "t2_airtime/test"
14
- require "t2_airtime/rest"
15
+ require "t2_airtime/util"
16
+ require "t2_airtime/serializer"
15
17
 
16
18
  module T2Airtime; end
data/t2_airtime.gemspec CHANGED
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_runtime_dependency 'dotenv-rails', '~> 2.2', '>= 2.2.1'
29
29
  spec.add_dependency "faraday", "0.9.1"
30
+ spec.add_dependency "countries", "2.1.2"
31
+ spec.add_dependency "money", "6.9.0"
30
32
 
31
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t2_airtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - matteolc
@@ -86,6 +86,34 @@ dependencies:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.9.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: countries
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '='
94
+ - !ruby/object:Gem::Version
95
+ version: 2.1.2
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '='
101
+ - !ruby/object:Gem::Version
102
+ version: 2.1.2
103
+ - !ruby/object:Gem::Dependency
104
+ name: money
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 6.9.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: 6.9.0
89
117
  description: Wrapper methods to interface with [TransferTo](https://www.transfer-to.com/home)
90
118
  Airtime API
91
119
  email:
@@ -108,9 +136,9 @@ files:
108
136
  - lib/t2_airtime/errors.rb
109
137
  - lib/t2_airtime/reply.rb
110
138
  - lib/t2_airtime/request.rb
111
- - lib/t2_airtime/rest.rb
112
- - lib/t2_airtime/test.rb
139
+ - lib/t2_airtime/serializer.rb
113
140
  - lib/t2_airtime/url.rb
141
+ - lib/t2_airtime/util.rb
114
142
  - lib/t2_airtime/version.rb
115
143
  - t2_airtime.gemspec
116
144
  homepage: https://github.com/matteolc/t2_airtime
@@ -1,78 +0,0 @@
1
- module T2Airtime
2
-
3
- class Country
4
-
5
- def self.all
6
- reply = T2Airtime::API.api.country_list
7
- reply.success? ? serialize_reply(reply.data) : []
8
- end
9
-
10
- def self.serialize_reply(data)
11
- names = data[:country].split(",")
12
- ids = data[:countryid].split(",")
13
- ids.each_with_index.map{|id, n| {
14
- name: names[n],
15
- aid: Integer(id)
16
- }}
17
- end
18
-
19
- end
20
-
21
- class Operator
22
-
23
- def self.all
24
- countries = T2Airtime::Country.all
25
- unless countries.empty?
26
- countries.flat_map{|country| (
27
- reply = T2Airtime::API.api.operator_list(country[:aid])
28
- reply.success? ? serialize_reply(reply.data) : []
29
- )}
30
- end
31
- end
32
-
33
- def self.serialize_reply(data)
34
- names = data[:operator].split(",")
35
- ids = data[:operatorid].split(",")
36
- ids.each_with_index.map{|id, n| {
37
- country: data[:country],
38
- country_aid: Integer(data[:countryid]),
39
- name: names[n],
40
- aid: Integer(id)
41
- }}
42
- end
43
-
44
- end
45
-
46
- class Product
47
-
48
- def self.all
49
- operators = T2Airtime::Operator.all
50
- unless operators.empty?
51
- operators.flat_map{|operator| (
52
- reply = T2Airtime::API.api.product_list(operator[:aid])
53
- reply.success? ? serialize_reply(reply.data) : []
54
- )}
55
- end
56
- end
57
-
58
- def self.serialize_reply(data)
59
- currency = data[:destination_currency]
60
- retail_prices = data[:retail_price_list].split(",")
61
- wholesale_prices = data[:wholesale_price_list].split(",")
62
- ids = data[:product_list].split(",")
63
- ids.each_with_index.map{|id, n| {
64
- country: data[:country],
65
- country_aid: Integer(data[:countryid]),
66
- operator: data[:operator],
67
- operator_aid: Integer(data[:operatorid]),
68
- name: "#{id}#{currency}",
69
- currency: currency,
70
- retail_price: retail_prices[n],
71
- wholesale_price: wholesale_prices[n],
72
- aid: Integer(id)
73
- }}
74
- end
75
-
76
- end
77
-
78
- end