class Blockcypher::Client::Api::Call

Public Class Methods

new(config) click to toggle source
# File lib/blockcypher/client/api.rb, line 32
def initialize(config)
  @config = config
  @http = HTTPClient.new(
    base_url: @config.base_uri.to_s,
    default_header: { Accept: 'application/json' }
  ) 
end

Public Instance Methods

get(path = '') click to toggle source
# File lib/blockcypher/client/api.rb, line 44
def get(path = '')
  perform(:get, path)
end
post(path, options = {}) click to toggle source
# File lib/blockcypher/client/api.rb, line 40
def post(path, options = {})
  perform(:post, path, options)
end

Private Instance Methods

params() click to toggle source
# File lib/blockcypher/client/api.rb, line 58
def params
  @config.token ? { token: @config.token } : {}
end
parse_json(response) click to toggle source
# File lib/blockcypher/client/api.rb, line 62
def parse_json(response)
  JSON.parse(response) 
end
perform(verb, path, options = {}) click to toggle source
# File lib/blockcypher/client/api.rb, line 50
def perform(verb, path, options = {})
  options.merge!(query: params)
  response = @http.public_send("#{verb.to_s}_content", path, options) 
  parse_json(response)
rescue HTTPClient::BadResponseError => e
  raise "Unexpected http status #{e.res.status} calling '#{e.res.header.request_uri.to_s}'"
end