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_csrf(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_csrf('/users/addtrustedaddress', request) end |
#get(url) ⇒ Faraday::Response
93 94 95 |
# File 'lib/cryptsy/web_client.rb', line 93 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_csrf('/users/login', request) end |
#make_withdrawal(currency_id, address, amount) ⇒ Faraday::Response
Submits a request for withdrawal to an untrusted address
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cryptsy/web_client.rb', line 78 def make_withdrawal(currency_id, address, amount) request = { 'data[Withdrawal][fee]' => '1.00000000', 'data[Withdrawal][wdamount]' => amount, 'data[Withdrawal][address]' => address, 'data[Withdrawal][approvedaddress]' => '', 'data[Withdrawal][existing_password]' => @password, 'data[Withdrawal][pincode]' => @tfa.now, } post_with_csrf("/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_csrf('/users/pincode', request) end |
#post(url, body) ⇒ Faraday::Response
100 101 102 |
# File 'lib/cryptsy/web_client.rb', line 100 def post(url, body) @connection.post(url, body) end |
#post_with_csrf(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
110 111 112 113 |
# File 'lib/cryptsy/web_client.rb', line 110 def post_with_csrf(url, request) prepare_request(get(url), request) post(url, request) end |