<commit_before>require 'httparty'

module BitcoinAverage
  module Requester
    def get(average, currency = 'USD')
      fail "#{currency} is not a known currency" unless known_currency?(currency)
      base_url = 'https://api.bitcoinaverage.com/ticker/'
      avg_url = average == 'global' ? average + '/' : ''
      ccy_url = currency
      final_url = base_url + avg_url + ccy_url

      HTTParty.get(final_url)
    end

    def known_currency?(currency)
      av_currencies = File.open('lib/bitcoinaverage/available_currencies.csv', 'r')
      .read
      .parse_csv
      true unless !av_currencies.include? currency
    end

    # Method to obtain all the available currencies
    #
    # Note: it's not run repeatedly, rather the result
    # was written to a file.
    # Note 2: "require 'csv' " is necessary for this method
    #
    #
    # def available_currencies
    #   all_ccy=HTTParty.get 'https://api.bitcoinaverage.com/ticker/global/all'
    #   all_ccy.map!{|k,v| k}
    #   file= File.open 'currencies_file.csv','w'
    #   file.write all_ccy[0..-2].to_csv
    #   file.close
    # end
  end
end
<commit_msg>Memoize available currencies<commit_after>require 'httparty'

module BitcoinAverage
  module Requester
    def get(average, currency = 'USD')
      fail "#{currency} is not a known currency" unless known_currency?(currency)
      base_url = 'https://api.bitcoinaverage.com/ticker/'
      avg_url = average == 'global' ? average + '/' : ''
      ccy_url = currency
      final_url = base_url + avg_url + ccy_url

      HTTParty.get(final_url)
    end

    def known_currency?(currency)
      available_currencies.include?(currency)
    end

    def available_currencies
      @available_currencies ||= File.open('lib/bitcoinaverage/available_currencies.csv', 'r').read.parse_csv
    end
  end
end

{'fraction_non_alphanumeric': 0.10964912280701754, 'fraction_numerical': 0.001644736842105263, 'mean_word_length': 2.98471615720524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6622700', 'n_tokens_mistral': 618, 'n_tokens_neox': 594, 'n_words': 136}