Class: Tastytrade::Client
- Inherits:
-
Object
- Object
- Tastytrade::Client
- Defined in:
- lib/tastytrade/client.rb
Overview
HTTP client wrapper for Tastytrade API communication
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #delete(path, headers = {}) ⇒ Object
- #get(path, params = {}, headers = {}) ⇒ Object
-
#initialize(base_url:, timeout: DEFAULT_TIMEOUT) ⇒ Client
constructor
A new instance of Client.
- #post(path, body = {}, headers = {}) ⇒ Object
- #put(path, body = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(base_url:, timeout: DEFAULT_TIMEOUT) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/tastytrade/client.rb', line 14 def initialize(base_url:, timeout: DEFAULT_TIMEOUT) @base_url = base_url @timeout = timeout end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/tastytrade/client.rb', line 10 def base_url @base_url end |
Instance Method Details
#delete(path, headers = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/tastytrade/client.rb', line 40 def delete(path, headers = {}) response = connection.delete(path, nil, default_headers.merge(headers)) handle_response(response) rescue Faraday::ConnectionFailed => e raise Tastytrade::NetworkTimeoutError, "Request timed out: #{e.}" end |
#get(path, params = {}, headers = {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/tastytrade/client.rb', line 19 def get(path, params = {}, headers = {}) response = connection.get(path, params, default_headers.merge(headers)) handle_response(response) rescue Faraday::ConnectionFailed => e raise Tastytrade::NetworkTimeoutError, "Request timed out: #{e.}" end |
#post(path, body = {}, headers = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/tastytrade/client.rb', line 26 def post(path, body = {}, headers = {}) response = connection.post(path, body.to_json, default_headers.merge(headers)) handle_response(response) rescue Faraday::ConnectionFailed => e raise Tastytrade::NetworkTimeoutError, "Request timed out: #{e.}" end |
#put(path, body = {}, headers = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/tastytrade/client.rb', line 33 def put(path, body = {}, headers = {}) response = connection.put(path, body.to_json, default_headers.merge(headers)) handle_response(response) rescue Faraday::ConnectionFailed => e raise Tastytrade::NetworkTimeoutError, "Request timed out: #{e.}" end |