Sha256: c6e91565c412265932ffdf3eb5e88619aab948ddf198e3c191251d3d5f3dcf13

Contents?: true

Size: 746 Bytes

Versions: 3

Compression:

Stored size: 746 Bytes

Contents

module Alphavantage
  class Client

    class << self
      def get(params:)
        default_params = { apikey: Alphavantage.configuration.api_key }
        response = Faraday.get('https://www.alphavantage.co/query') do |req|
          req.params = default_params.merge(params)
          req.headers['Content-Type'] = 'application/json'
        end
        Hashie::Mash.new(convert_hash_keys(JSON.parse(response.body)))
      end

      def convert_hash_keys(value)
        case value
          when Array
            value.map { |v| convert_hash_keys(v) }
          when Hash
            Hash[value.map { |k, v| [ NormalizeKey.new(key: k).call, convert_hash_keys(v) ] }]
          else
            value
         end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alphavantage-1.1.0 lib/alphavantage/client.rb
alphavantage-1.0.2 lib/alphavantage/client.rb
alphavantage-1.0.1 lib/alphavantage/client.rb