Sha256: b362406299e27f3f86df629f010c85579fad566cb94d891dba2466877c94c794

Contents?: true

Size: 650 Bytes

Versions: 1

Compression:

Stored size: 650 Bytes

Contents

# frozen_string_literal: true

require 'coinmarketcap_free/helper'

module CoinmarketcapFree
  class BASE
    protected

    def request_to_read_data(url)
      response = Net::HTTP.get_response(url, Hash('Accept': '*/*'))

      raise HTTPBadResponse if response.code.match? /[45][0-9]{2}/

      response.read_body
    end

    def generate_uri_for_data
      raise NotImplementedError
    end

    public

    attr_reader :data

    def update
      begin
        url = generate_uri_for_data
        @data = request_to_read_data(url)
      rescue
        false
      else
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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