Class: Fbox::Client
- Inherits:
-
Object
- Object
- Fbox::Client
- Defined in:
- lib/fbox/client.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :site => 'https://faucetbox.com', :context_path => '', :rest_base_path => "/api/v1/", :ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :use_ssl => true, :api_key => '', }
- FBOX_API =
{ :balance => 'balance', :currencies => 'currencies', :payment => 'send', :payouts => 'payouts', }
- @@addres_validator =
nil
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #balance(currency = '') ⇒ Object
- #currencies ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #is_address_valid?(address) ⇒ Boolean
- #is_response_ok?(body) ⇒ Boolean
- #payment(to, amount, referral = false, currency = '') ⇒ Object
-
#payouts(count = 1, currency = '') ⇒ Object
Use with care it gives timeouts, probably this API call is disabled on FaucetBox.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fbox/client.rb', line 51 def initialize(={}) @@addres_validator = CoinsAddressValidator::Validator.new = DEFAULT_OPTIONS.merge() = [:rest_base_path] = [:context_path] + [:rest_base_path] @request_client = HttpClient.new() .freeze end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/fbox/client.rb', line 31 def end |
Instance Method Details
#balance(currency = '') ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/fbox/client.rb', line 62 def balance(currency = '') path = prepare_api_request(FBOX_API[:balance]) form_params = { 'api_key' => [:api_key], 'currency' => !currency.empty? ? currency : 'BTC' } response = request(path, form_params) process_response(response) end |
#currencies ⇒ Object
90 91 92 93 94 |
# File 'lib/fbox/client.rb', line 90 def currencies() path = prepare_api_request(FBOX_API[:currencies]) response = request(path) process_response(response) end |
#is_address_valid?(address) ⇒ Boolean
117 118 119 |
# File 'lib/fbox/client.rb', line 117 def is_address_valid?(address) @@addres_validator.is_address_valid?(address) end |
#is_response_ok?(body) ⇒ Boolean
113 114 115 |
# File 'lib/fbox/client.rb', line 113 def is_response_ok?(body) body['status'].present? && body['status'] == 200 end |
#payment(to, amount, referral = false, currency = '') ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fbox/client.rb', line 96 def payment(to, amount, referral = false, currency = '') if !to.empty? && self.is_address_valid?(to) && amount > 0 path = prepare_api_request(FBOX_API[:payment]) form_params = { 'api_key' => [:api_key], 'to' => to, 'amount' => amount, 'currency' => !currency.empty? ? currency : 'BTC', 'referral' => referral.to_s } response = request(path, form_params) process_response(response) else nil end end |
#payouts(count = 1, currency = '') ⇒ Object
Use with care it gives timeouts, probably this API call is disabled on FaucetBox
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fbox/client.rb', line 75 def payouts(count = 1, currency = '') if count.to_i > 0 && count <= 10 path = prepare_api_request(FBOX_API[:payouts]) form_params = { 'api_key' => [:api_key], 'count' => count, 'currency' => !currency.empty? ? currency : 'BTC' } response = request(path, form_params) process_response(response) else invalid_parameter("'count' parameter has to be in 1..10 range") end end |