Module: CoinbaseCustody::Util
- Included in:
- Client
- Defined in:
- lib/coinbase_custody/util.rb
Overview
Utility file for general methods
Constant Summary collapse
- BASE_API_URL =
COINBASE_CUSTODY_CONFIG[:url]
Instance Method Summary collapse
- #format_response(response) ⇒ Object
- #pagination_params(headers = {}) ⇒ Object
- #send_request(path) ⇒ Object
Instance Method Details
#format_response(response) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/coinbase_custody/util.rb', line 18 def format_response(response) { status: response.code, result: (JSON.parse(response.body) rescue response.body), pagination: pagination_params(response.headers) } end |
#pagination_params(headers = {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/coinbase_custody/util.rb', line 26 def pagination_params(headers = {}) if headers['cb-before'].blank? || headers['cb-after'].blank? return {} end { before: headers['cb-before'], after: headers['cb-after'] } end |
#send_request(path) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/coinbase_custody/util.rb', line 8 def send_request(path) headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => 'request' } response = HTTParty.get("#{BASE_API_URL}#{path}", headers: headers) format_response(response) end |