Sha256: 6aa15301e775fec2feceaa05cbe0e35fa4a71d894c559638de083074a4fe90de

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require 'coinmarketcap_free/helper'
require 'coinmarketcap_free/base'

module CoinmarketcapFree
  # Returns an interval of historic market quotes for any cryptocurrency based on time and interval parameters.
  #
  # For example, json data
  #
  # {
  #     "data": {
  #         "points": {
  #             "1673192010": {
  #               "v": [
  #                     16953.771282696678,
  #                     7609543976.45,
  #                     326457581376.786557398500,
  #                     1,
  #                     19255750.00000000000000000000
  #                 ],
  #                 "c": [
  #                     16953.771282696678,
  #                     7609543976.45,
  #                     326457581376.786557398500
  #                 ]
  #             },
  #           ...
  #         }
  #     },
  #     "status": {
  #         "timestamp": "2023-01-08T15:33:30.271Z",
  #         "error_code": "0",
  #         "error_message": "SUCCESS",
  #         "elapsed": "2",
  #         "credit_count": 0
  #     }
  # }
  #
  # 'data' - Results of your query returned as an object map.
  #   'points' - Price range history
  # 'status' - Standardized status object for API calls.
  class Coin < BASE
    URL_API = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail/chart'.freeze
    private_constant :URL_API

    attr_accessor :id,
                  :range_time

    # id Integer. Cryptocurrency identifier from coinmarketcap. For example, Bitcoin has the number 1
    # range_time String. Range time. For example, '1D', '7D', '1M', '3M', '1Y', 'YTD', 'ALL' or custom range '1668981600~1671659999'
    def initialize(id, range_time)
      @id = id
      @range_time = range_time
    end

    def generate_uri_for_data
      query = "#{URL_API}?id=#{id}&range=#{range_time}"
      URI(query)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coinmarketcap_free-0.1.0 lib/coinmarketcap_free/coin.rb