class Cryptowatch::RestClientAdapter

Attributes

options[RW]

Public Class Methods

new(options) click to toggle source
# File lib/cryptowatch/adapter/rest_client_adapter.rb, line 17
def initialize (options)
  @options = options
end

Public Instance Methods

get(*elements) click to toggle source
# File lib/cryptowatch/adapter/rest_client_adapter.rb, line 21
def get (*elements)

  if (elements.size == 0)
     Messages::LOG.error(Messages::ERROR_NO_URL)
    return nil
  end

  url = Api::format_url(*elements)

  begin
    milli_start = Time.now
    answer = JSON.parse(RestClient::Request.execute(
      method: :get,
      url: url,
      timeout: @options[:timeout]),
      accept: :json
    )
    milli_end = Time.now
    elapsed   = Utils::time_elapsed(milli_start, milli_end)
    Messages::LOG.info("[#{elapsed.round} ms] #{Messages::GET}'#{url}'")
    return answer
  rescue SocketError, RestClient::ExceptionWithResponse => e
    Messages::LOG.error("'#{e.message}' on => #{url}")
  end
end