Sha256: 928eb44b1977a0f8cf140340879d06678f28c60591bf9ec8c63bfd57a680e04b

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 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 url
      #   "#{BASE_URL}/#{action}?#{query}"
      # end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itunes_api-0.5.0 lib/itunes_api/requests/base.rb
itunes_api-0.4.2 lib/itunes_api/requests/base.rb