Class: T2Airtime::Request
- Inherits:
-
Object
- Object
- T2Airtime::Request
- Defined in:
- lib/t2_airtime/request.rb
Instance Method Summary collapse
- #add_param(key, value) ⇒ Object
- #authenticate ⇒ Object
- #get? ⇒ Boolean
-
#initialize(user, password, url, name, params) ⇒ Request
constructor
A new instance of Request.
- #key ⇒ Object
- #post? ⇒ Boolean
- #reset ⇒ Object
-
#run(method = :get) ⇒ Object
More than 99.5% of the transactions are currently processed within a few seconds.
Constructor Details
#initialize(user, password, url, name, params) ⇒ Request
Returns a new instance of Request
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/t2_airtime/request.rb', line 4 def initialize(user, password, url, name, params) @user = user || "" @pass = password || "" @conn = Faraday.new(url: url) do |faraday| faraday.request :url_encoded faraday.adapter :net_http end reset @name = name add_param :action, name @params.merge!(params) end |
Instance Method Details
#add_param(key, value) ⇒ Object
29 |
# File 'lib/t2_airtime/request.rb', line 29 def add_param(key, value) @params[key.to_sym] = value end |
#authenticate ⇒ Object
22 23 24 25 26 27 |
# File 'lib/t2_airtime/request.rb', line 22 def authenticate time = Time.now.to_i.to_s add_param :key, time add_param :md5, md5_hash(@user + @pass + time) add_param :login, @user end |
#get? ⇒ Boolean
33 |
# File 'lib/t2_airtime/request.rb', line 33 def get?() @params[:method] == :get end |
#key ⇒ Object
31 |
# File 'lib/t2_airtime/request.rb', line 31 def key() @params[:key] end |
#post? ⇒ Boolean
35 |
# File 'lib/t2_airtime/request.rb', line 35 def post?() @params[:method] == :post end |
#reset ⇒ Object
17 18 19 20 |
# File 'lib/t2_airtime/request.rb', line 17 def reset @params = {} authenticate end |
#run(method = :get) ⇒ Object
More than 99.5% of the transactions are currently processed within a few seconds. However, it may happen in some rare cases that a transaction takes longer to be processed by the receiving operator due to congested system on their end for instance. TransferTo guarantees that transactions not processed within 600 seconds will not be charged, whatever the final status of the transaction (successful or not). In addition, TransferTo is operating a real time system; therefore, the status returned in the Top-up response is final and will not change. To ensure that your system captures successfully the status of all transactions especially the longest ones, it is advised to either set up a high timeout value of 600seconds to be on the safe side (TCP connection could potentially be opened for a long time in this case) or to set up a mechanism to check on the status (to do so, you can call the trans_info method to retrieve the final status of a transaction). In case of timeout, both methods reserve_id and get_id_from_key of the API could be useful to identify the ID of the transaction (we recommend to either send a reserve_id request and to use the ID returned in the response in the subsequent top-up request so that you know in advance the ID of the transaction).
50 51 52 53 54 55 |
# File 'lib/t2_airtime/request.rb', line 50 def run(method = :get) add_param :method, method @conn.send(method, "/#{T2Airtime::ENDPOINT}", @params) do |req| req. = { timeout: 600, open_timeout: 600 } end end |