Sha256: 4cb405e5aeb3e0c8acabe21008ebd5ec5bb30c71f165caec89a65edfb62dcb62

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

require 'pp'
require 'json'
require 'net/http'

module Mcoin
  module Market
    # :nodoc:
    class Base
      def initialize(type, currency)
        @type = type
        @currency = currency
        @retries = 0
      end

      def name
        self.class.name.split('::').last
      end

      def fetch
        @data ||= JSON.parse(Net::HTTP.get(uri))
        self
      rescue JSON::ParserError
        raise if @retries >= 3
        @retries += 1
        retry
      end

      def to_ticker
        raise NotImplementedError
      end

      def uri
        options = { type: @type.upcase, currency: @currency.upcase }
        uri = format(self.class.const_get(:ENDPOINT), options)
        URI(uri)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mcoin-0.3.0 lib/mcoin/market/base.rb
mcoin-0.2.1 lib/mcoin/market/base.rb