Sha256: a62a5386aeb399d7b0cbbeec7a86e07f082a0c0e08a2de2d6101047080a425e4

Contents?: true

Size: 728 Bytes

Versions: 7

Compression:

Stored size: 728 Bytes

Contents

require 'faraday'
require 'json'
module ItunesApi
  module Requests
    # Allow requests to the iTunes API.
    module Base
      def results
        @results ||= parsed_response.fetch('results') { [] }
      end

      private

      def parsed_response
        JSON.parse(response.body)
      end

      def connection
        Faraday.new(url: BASE_URL)
      end

      def response
        connection.get(action, query)
      end

      def symbolize_keys(hash)
        hash.each_with_object({}) do |(key, value), new_hash|
          new_hash[key.to_sym] = value
          new_hash
        end
      end

      def unwrapped(data_hash)
        data_hash.tap { |hash| hash.delete('wrapperType') }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
itunes_api-1.4.1 lib/itunes_api/requests/base.rb
itunes_api-1.4.0 lib/itunes_api/requests/base.rb
itunes_api-1.3.1 lib/itunes_api/requests/base.rb
itunes_api-1.3 lib/itunes_api/requests/base.rb
itunes_api-1.2.1 lib/itunes_api/requests/base.rb
itunes_api-1.2.0 lib/itunes_api/requests/base.rb
itunes_api-1.1.0 lib/itunes_api/requests/base.rb