t2_airtime 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/t2_airtime/api.rb +14 -22
- data/lib/t2_airtime/base.rb +1 -3
- data/lib/t2_airtime/reply.rb +16 -35
- data/lib/t2_airtime/rest.rb +31 -20
- data/lib/t2_airtime/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f76c758dc19f0a18801723bce129f79b3901ef2
|
4
|
+
data.tar.gz: 939e2277d01c62ef4d24ca7f772305352e0569c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d734a1bd8ac1b49d86311205f4d4be15b0c3728de5132a440f6816010f529ef413cabf0dbfec74fb07adfd4effd8908cf568234499fe36e7820b43394f17d9f
|
7
|
+
data.tar.gz: 2f0f8aa5be119dda169c520b01c54cea00804c452f0d612c53f28fdffb90d280c330cd908984960149e633e3d6aefb69772af8970e1cbb244366302529169710
|
data/lib/t2_airtime/api.rb
CHANGED
@@ -146,7 +146,8 @@ module T2Airtime
|
|
146
146
|
# portability if you are able to know the destination operator.
|
147
147
|
# return_promo
|
148
148
|
# Setting this to “1” will return the current promotion related to the transaction’s operator.
|
149
|
-
def msisdn_info(destination_msisdn,
|
149
|
+
def msisdn_info(destination_msisdn,
|
150
|
+
operator_id=nil,
|
150
151
|
delivered_amount_info=1, return_service_fee=1, return_promo=1)
|
151
152
|
@params = {
|
152
153
|
destination_msisdn: destination_msisdn,
|
@@ -157,13 +158,6 @@ module T2Airtime
|
|
157
158
|
self.oid = operator_id
|
158
159
|
run_action :msisdn_info
|
159
160
|
end
|
160
|
-
|
161
|
-
# Get information about a phone number
|
162
|
-
def phone_search(number, operator_id=nil)
|
163
|
-
information = msisdn_info(number, operator_id).information
|
164
|
-
information[:product_list] = information[:product_list].split(",")
|
165
|
-
information
|
166
|
-
end
|
167
161
|
|
168
162
|
# This method is used to reserve an ID in the system. This ID can then be
|
169
163
|
# used in the “topup” or “simulation” requests.
|
@@ -241,34 +235,32 @@ module T2Airtime
|
|
241
235
|
# i) Not used if info_type = “countries”
|
242
236
|
# ii) countryid of the requested country if info_type = “country”
|
243
237
|
# iii) operatorid of the requested operator if info_type = “operator”
|
244
|
-
|
245
238
|
def price_list(info_type, content=nil)
|
246
239
|
@params[:info_type] = info_type
|
247
240
|
content && @params[:content] = content
|
248
241
|
run_action :pricelist
|
249
242
|
end
|
250
243
|
|
251
|
-
|
252
|
-
|
253
|
-
end
|
244
|
+
# Convenience method to get the country list
|
245
|
+
def country_list() price_list('countries') end
|
254
246
|
|
255
|
-
|
256
|
-
|
257
|
-
end
|
247
|
+
# Convenience method to get the operators list for a given country
|
248
|
+
# @country_aid the airtime id of the country
|
249
|
+
def operator_list(country_aid) price_list('country', country_aid) end
|
258
250
|
|
259
|
-
|
260
|
-
|
261
|
-
end
|
251
|
+
# Convenience method to get the product list for a given operator
|
252
|
+
# @operator_aid the airtime id of the operator
|
253
|
+
def product_list(operator_aid) price_list('operator', operator_aid) end
|
262
254
|
|
263
255
|
# Operator Logo URL
|
264
|
-
def operator_logo_url(
|
265
|
-
"#{T2Airtime::PROTOCOL}://#{T2Airtime::OPLOGO_DN}.#{T2Airtime::DOMAIN}/logo-#{
|
256
|
+
def operator_logo_url(operator_aid, size=1)
|
257
|
+
"#{T2Airtime::PROTOCOL}://#{T2Airtime::OPLOGO_DN}.#{T2Airtime::DOMAIN}/logo-#{operator_aid}-#{size}.png"
|
266
258
|
end
|
267
259
|
|
268
260
|
private
|
269
261
|
|
270
|
-
def oid=(
|
271
|
-
@params[:operatorid] =
|
262
|
+
def oid=(operator_aid)
|
263
|
+
operator_aid.is_a?(Integer) && @params[:operatorid] = Integer(operator_aid)
|
272
264
|
end
|
273
265
|
|
274
266
|
def to_time(time)
|
data/lib/t2_airtime/base.rb
CHANGED
@@ -16,9 +16,7 @@ module T2Airtime
|
|
16
16
|
def run_action(name, method=:get)
|
17
17
|
request = T2Airtime::Request.new(@user, @password, @url, name, @params)
|
18
18
|
request.run(method).on_complete do |reply|
|
19
|
-
|
20
|
-
#raise ::T2Airtime::Error.new @reply.error_code, @reply.error_message unless @reply.success?
|
21
|
-
return reply.data
|
19
|
+
return T2Airtime::Reply.new(reply)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
data/lib/t2_airtime/reply.rb
CHANGED
@@ -1,58 +1,39 @@
|
|
1
1
|
module T2Airtime
|
2
2
|
class Reply
|
3
3
|
|
4
|
-
def initialize(reply)
|
5
|
-
@response = reply.to_hash
|
6
|
-
end
|
4
|
+
def initialize(reply) @response = Hash(reply) end
|
7
5
|
|
8
6
|
def data
|
9
7
|
hash = {}
|
10
8
|
@response[:body].lines.each do |line|
|
11
9
|
key, value = line.strip.split "="
|
12
|
-
hash[key.to_sym] = (key == "error_code") ? value
|
10
|
+
hash[key.to_sym] = (key == "error_code") ? Integer(value) : value
|
13
11
|
end; hash
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
|
14
|
+
def information
|
15
|
+
data.reject do |key, value|
|
16
|
+
[:authentication_key, :error_code, :error_txt].include?(key)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def error_code
|
21
|
-
data[:error_code]
|
22
|
-
end
|
20
|
+
def success?() status == 200 && error_code == 0 end
|
23
21
|
|
24
|
-
def
|
25
|
-
data[:error_txt]
|
26
|
-
end
|
22
|
+
def status() @response[:status] end
|
27
23
|
|
28
|
-
def
|
29
|
-
status == 200 && error_code == 0
|
30
|
-
end
|
24
|
+
def error_code() data[:error_code] end
|
31
25
|
|
32
|
-
def
|
33
|
-
@response[:url].to_s
|
34
|
-
end
|
26
|
+
def error_message() data[:error_txt] end
|
35
27
|
|
36
|
-
def
|
37
|
-
data.reject do |key, value|
|
38
|
-
[:authentication_key, :error_code, :error_txt].include?(key)
|
39
|
-
end
|
40
|
-
end
|
28
|
+
def url() "#{@response[:url]}" end
|
41
29
|
|
42
|
-
def message
|
43
|
-
information[:info_txt]
|
44
|
-
end
|
30
|
+
def message() information[:info_txt] end
|
45
31
|
|
46
|
-
def auth_key
|
47
|
-
data[:authentication_key]
|
48
|
-
end
|
32
|
+
def auth_key() data[:authentication_key] end
|
49
33
|
|
50
|
-
def headers
|
51
|
-
|
52
|
-
end
|
34
|
+
def headers() @response[:response_headers] end
|
35
|
+
|
36
|
+
def raw() @response[:body] end
|
53
37
|
|
54
|
-
def raw
|
55
|
-
@response[:body]
|
56
|
-
end
|
57
38
|
end
|
58
39
|
end
|
data/lib/t2_airtime/rest.rb
CHANGED
@@ -3,12 +3,13 @@ module T2Airtime
|
|
3
3
|
class Country
|
4
4
|
|
5
5
|
def self.all
|
6
|
-
|
6
|
+
reply = T2Airtime::API.api.country_list
|
7
|
+
reply.success? ? serialize_reply(reply.data) : []
|
7
8
|
end
|
8
9
|
|
9
|
-
def self.serialize_reply(
|
10
|
-
names =
|
11
|
-
ids =
|
10
|
+
def self.serialize_reply(data)
|
11
|
+
names = data[:country].split(",")
|
12
|
+
ids = data[:countryid].split(",")
|
12
13
|
ids.each_with_index.map{|id, n| {
|
13
14
|
name: names[n],
|
14
15
|
aid: Integer(id)
|
@@ -21,15 +22,20 @@ module T2Airtime
|
|
21
22
|
|
22
23
|
def self.all
|
23
24
|
countries = T2Airtime::Country.all
|
24
|
-
countries.
|
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
|
25
31
|
end
|
26
32
|
|
27
|
-
def self.serialize_reply(
|
28
|
-
names =
|
29
|
-
ids =
|
33
|
+
def self.serialize_reply(data)
|
34
|
+
names = data[:operator].split(",")
|
35
|
+
ids = data[:operatorid].split(",")
|
30
36
|
ids.each_with_index.map{|id, n| {
|
31
|
-
country:
|
32
|
-
country_aid: Integer(
|
37
|
+
country: data[:country],
|
38
|
+
country_aid: Integer(data[:countryid]),
|
33
39
|
name: names[n],
|
34
40
|
aid: Integer(id)
|
35
41
|
}}
|
@@ -41,19 +47,24 @@ module T2Airtime
|
|
41
47
|
|
42
48
|
def self.all
|
43
49
|
operators = T2Airtime::Operator.all
|
44
|
-
operators.
|
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
|
45
56
|
end
|
46
57
|
|
47
|
-
def self.serialize_reply(
|
48
|
-
currency =
|
49
|
-
retail_prices =
|
50
|
-
wholesale_prices =
|
51
|
-
ids =
|
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(",")
|
52
63
|
ids.each_with_index.map{|id, n| {
|
53
|
-
country:
|
54
|
-
country_aid: Integer(
|
55
|
-
operator:
|
56
|
-
operator_aid: Integer(
|
64
|
+
country: data[:country],
|
65
|
+
country_aid: Integer(data[:countryid]),
|
66
|
+
operator: data[:operator],
|
67
|
+
operator_aid: Integer(data[:operatorid]),
|
57
68
|
name: "#{id}#{currency}",
|
58
69
|
currency: currency,
|
59
70
|
retail_price: retail_prices[n],
|
data/lib/t2_airtime/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: t2_airtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matteolc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|