Class: TransferTo::Request
- Inherits:
-
Object
- Object
- TransferTo::Request
- Defined in:
- lib/transfer_to/request.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #action=(name) ⇒ Object
- #add_param(key, value) ⇒ Object
- #authenticate ⇒ Object
- #get? ⇒ Boolean
-
#initialize(user, password, aurl = nil) ⇒ Request
constructor
A new instance of Request.
- #key ⇒ Object
- #post? ⇒ Boolean
- #reset ⇒ Object
- #run(method = :get) ⇒ Object
Constructor Details
#initialize(user, password, aurl = nil) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 |
# File 'lib/transfer_to/request.rb', line 6 def initialize(user, password, aurl = nil) @user = user @pass = password @conn = Faraday.new(url: aurl) do |faraday| faraday.request :url_encoded faraday.adapter :net_http end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/transfer_to/request.rb', line 4 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/transfer_to/request.rb', line 4 def params @params end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/transfer_to/request.rb', line 4 def user @user end |
Instance Method Details
#action=(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/transfer_to/request.rb', line 27 def action=(name) reset @name = name add_param :action, name end |
#add_param(key, value) ⇒ Object
37 38 39 |
# File 'lib/transfer_to/request.rb', line 37 def add_param(key, value) @params[key.to_sym] = value end |
#authenticate ⇒ Object
20 21 22 23 24 25 |
# File 'lib/transfer_to/request.rb', line 20 def authenticate time = Time.now.to_i.to_s add_param :key, time add_param :md5, md5_hash(@user + @pass + time.to_s) add_param :login, @user end |
#get? ⇒ Boolean
45 46 47 |
# File 'lib/transfer_to/request.rb', line 45 def get? @params[:method] == :get end |
#key ⇒ Object
41 42 43 |
# File 'lib/transfer_to/request.rb', line 41 def key @params[:key] end |
#post? ⇒ Boolean
49 50 51 |
# File 'lib/transfer_to/request.rb', line 49 def post? @params[:method] == :post end |
#reset ⇒ Object
15 16 17 18 |
# File 'lib/transfer_to/request.rb', line 15 def reset @params = {} authenticate end |
#run(method = :get) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/transfer_to/request.rb', line 53 def run(method = :get) add_param :method, method @conn.send(method, "/cgi-bin/shop/topup", @params) do |req| req. = { timeout: 600, open_timeout: 600 } end end |