class CryptoVal::List::CryptoCoinCharts

Public Class Methods

fetch() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 8
def self.fetch
  new.fetch
end

Public Instance Methods

fetch() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 4
def fetch
  format_response
end

Private Instance Methods

base_url() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 14
def base_url
  "https://api.cryptocoincharts.info"
end
format_response() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 38
def format_response
  list = []
  parsed.each do |data|
    if data.is_a?(Hash)
      list << { 
                symbol: data["id"].upcase, 
                name: data["name"] 
              }
    end
  end
  list
end
get_response() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 26
def get_response
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(uri.request_uri)
  http.request(request).body
end
parsed() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 34
def parsed
  @parsed ||= JSON.parse(response)
end
response() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 22
def response
  @response ||= get_response
end
url() click to toggle source
# File lib/crypto_val/list/crypto_coin_charts.rb, line 18
def url
  "#{base_url}/listCoins"
end