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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6e8d1b5cfa93a9f398cc58bd1089bfc128a0dd0
4
- data.tar.gz: e75396f390b165e992e87e37d75557fb82a7c427
3
+ metadata.gz: 4f76c758dc19f0a18801723bce129f79b3901ef2
4
+ data.tar.gz: 939e2277d01c62ef4d24ca7f772305352e0569c5
5
5
  SHA512:
6
- metadata.gz: ae9a53249041d93c36146080f8cefa03052c5d90b32afe117d097f0333b68c835672a0aad09aefe1bdf0a61204a328371c52331a6bb1eb1010569aee16c2ff1d
7
- data.tar.gz: 764234e7bfbfd290da1effb363c223ad7c21193df6e30c10ed5c200b674db654324ea18d2d2505cbf2e66adb5cf0032b9a3c0c50abc1e7b8ff010d82d8b40f99
6
+ metadata.gz: 7d734a1bd8ac1b49d86311205f4d4be15b0c3728de5132a440f6816010f529ef413cabf0dbfec74fb07adfd4effd8908cf568234499fe36e7820b43394f17d9f
7
+ data.tar.gz: 2f0f8aa5be119dda169c520b01c54cea00804c452f0d612c53f28fdffb90d280c330cd908984960149e633e3d6aefb69772af8970e1cbb244366302529169710
@@ -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, operator_id=nil,
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
- def country_list
252
- price_list('countries')
253
- end
244
+ # Convenience method to get the country list
245
+ def country_list() price_list('countries') end
254
246
 
255
- def operator_list(country_api_id)
256
- price_list('country', country_api_id)
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
- def product_list(operator_api_id)
260
- price_list('operator', operator_api_id)
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(operator_id, size=1)
265
- "#{T2Airtime::PROTOCOL}://#{T2Airtime::OPLOGO_DN}.#{T2Airtime::DOMAIN}/logo-#{operator_id}-#{size}.png"
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=(operator_id)
271
- @params[:operatorid] = operator_id.to_i if operator_id.is_a?(Integer)
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)
@@ -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
- reply = T2Airtime::Reply.new(reply)
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
 
@@ -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.to_i : value
10
+ hash[key.to_sym] = (key == "error_code") ? Integer(value) : value
13
11
  end; hash
14
12
  end
15
13
 
16
- def status
17
- @response[:status]
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 error_message
25
- data[:error_txt]
26
- end
22
+ def status() @response[:status] end
27
23
 
28
- def success?
29
- status == 200 && error_code == 0
30
- end
24
+ def error_code() data[:error_code] end
31
25
 
32
- def url
33
- @response[:url].to_s
34
- end
26
+ def error_message() data[:error_txt] end
35
27
 
36
- def information
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
- @response[:response_headers]
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
@@ -3,12 +3,13 @@ module T2Airtime
3
3
  class Country
4
4
 
5
5
  def self.all
6
- serialize_reply(T2Airtime::API.api.country_list)
6
+ reply = T2Airtime::API.api.country_list
7
+ reply.success? ? serialize_reply(reply.data) : []
7
8
  end
8
9
 
9
- def self.serialize_reply(reply)
10
- names = reply[:country].split(",")
11
- ids = reply[:countryid].split(",")
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.flat_map{|country| serialize_reply(T2Airtime::API.api.operator_list(country[:aid]))}
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(reply)
28
- names = reply[:operator].split(",")
29
- ids = reply[:operatorid].split(",")
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: reply[:country],
32
- country_aid: Integer(reply[:countryid]),
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.flat_map{|operator| serialize_reply(T2Airtime::API.api.product_list(operator[:aid]))}
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(reply)
48
- currency = reply[:destination_currency]
49
- retail_prices = reply[:retail_price_list].split(",")
50
- wholesale_prices = reply[:wholesale_price_list].split(",")
51
- ids = reply[:product_list].split(",")
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: reply[:country],
54
- country_aid: Integer(reply[:countryid]),
55
- operator: reply[:operator],
56
- operator_aid: Integer(reply[:operatorid]),
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],
@@ -1,3 +1,3 @@
1
1
  module T2Airtime
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-26 00:00:00.000000000 Z
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler