Class: Cryptsy::WebClient
- Inherits:
-
Object
- Object
- Cryptsy::WebClient
- Defined in:
- lib/cryptsy/web_client.rb
Overview
Unsafe client that allows you to do things that the Cryptsy API does not permit, including withdrawals to untrusted addresses, as well as pre-approving addresses for withdrawals
Constant Summary collapse
- DEFAULT_OPTIONS =
{ url: 'https://www.cryptsy.com' }
Instance Attribute Summary collapse
- #cookie_jar ⇒ Object readonly
Instance Method Summary collapse
-
#add_trusted_address(currency_id, address) ⇒ Faraday::Response
Submits a trusted address for pre-approved withdrawals.
- #get(url) ⇒ Faraday::Response
-
#initialize(username, password, tfa_secret, options = {}) ⇒ WebClient
constructor
A new instance of WebClient.
-
#login ⇒ Faraday::Response
Performs login operation using the configured username and password.
-
#make_withdrawal(currency_id, address, amount) ⇒ Faraday::Response
Submits a request for withdrawal to an untrusted address.
-
#pincode ⇒ Faraday::Response
Finishes login operation using TOTP and TFA secret.
- #post(url, body) ⇒ Faraday::Response
-
#post_with_token(url, request) ⇒ Faraday::Request
Performs an initial GET request to the given URL to obtain any CSRF tokens, injects them into the given request, then performs a POST request to the given URL.
Constructor Details
#initialize(username, password, tfa_secret, options = {}) ⇒ WebClient
Returns a new instance of WebClient.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cryptsy/web_client.rb', line 21 def initialize(username, password, tfa_secret, = {}) @username = username @password = password @tfa = ROTP::TOTP.new(tfa_secret) @cookie_jar = HTTP::CookieJar.new @connection = Faraday.new(DEFAULT_OPTIONS.merge()) do |builder| builder.use :cookie_jar, jar: @cookie_jar builder.request :url_encoded builder.adapter Faraday.default_adapter end end |
Instance Attribute Details
#cookie_jar ⇒ Object (readonly)
15 16 17 |
# File 'lib/cryptsy/web_client.rb', line 15 def @cookie_jar end |
Instance Method Details
#add_trusted_address(currency_id, address) ⇒ Faraday::Response
Submits a trusted address for pre-approved withdrawals
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cryptsy/web_client.rb', line 61 def add_trusted_address(currency_id, address) request = { 'data[Withdrawal][currency_id]' => currency_id, 'data[Withdrawal][address]' => address, 'data[Withdrawal][existing_password]' => @password, 'data[Withdrawal][pincode]' => @tfa.now, } post_with_token('/users/addtrustedaddress', request) end |
#get(url) ⇒ Faraday::Response
95 96 97 |
# File 'lib/cryptsy/web_client.rb', line 95 def get(url) @connection.get(url) end |
#login ⇒ Faraday::Response
Performs login operation using the configured username and password
37 38 39 40 41 42 43 44 |
# File 'lib/cryptsy/web_client.rb', line 37 def login request = { 'data[User][username]' => @username, 'data[User][password]' => @password, } post_with_token('/users/login', request) end |
#make_withdrawal(currency_id, address, amount) ⇒ Faraday::Response
Submits a request for withdrawal to an untrusted address
Note that this will only work for addresses that have not been trusted. Use the JSON API for withdrawing to trusted addresses.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cryptsy/web_client.rb', line 81 def make_withdrawal(currency_id, address, amount) request = { 'data[Withdrawal][fee]' => '1.00000000', 'data[Withdrawal][wdamount]' => amount, 'data[Withdrawal][address]' => address, 'data[Withdrawal][existing_password]' => @password, 'data[Withdrawal][pincode]' => @tfa.now, } post_with_token("/users/makewithdrawal/#{currency_id}", request) end |
#pincode ⇒ Faraday::Response
Finishes login operation using TOTP and TFA secret
48 49 50 51 52 53 54 |
# File 'lib/cryptsy/web_client.rb', line 48 def pincode request = { 'data[User][pincode]' => @tfa.now } post_with_token('/users/pincode', request) end |
#post(url, body) ⇒ Faraday::Response
102 103 104 |
# File 'lib/cryptsy/web_client.rb', line 102 def post(url, body) @connection.post(url, body) end |
#post_with_token(url, request) ⇒ Faraday::Request
Performs an initial GET request to the given URL to obtain any CSRF tokens, injects them into the given request, then performs a POST request to the given URL
112 113 114 115 |
# File 'lib/cryptsy/web_client.rb', line 112 def post_with_token(url, request) prepare_request(get(url), request) post(url, request) end |