Sha256: d7ce5250a19c6758b33cd30ec193bb755f8155c2fb0f4ec78be248fa8a705941

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

Dir[File.dirname(__FILE__) + '/remote_api/*.rb'].each { |file| require file }

module Songkickr
  # Create an instance of the remote class to interact with the Songkick API.
  class Remote
    include HTTParty
    include Songkickr::RemoteApi::UpcomingEvents
    include Songkickr::RemoteApi::UserEventsAndTrackings
    include Songkickr::RemoteApi::PastEvents
    include Songkickr::RemoteApi::ArtistDetails
    include Songkickr::RemoteApi::EventDetails
    include Songkickr::RemoteApi::VenueDetails
    include Songkickr::RemoteApi::SimilarArtists

    attr_accessor :debug
    attr_reader :api_key

    base_uri 'api.songkick.com/api/3.0'
    format :json

    # ==== Create a new instance of the remote class to talk to Songkick
    # Get an API key for your app from http://developer.songkick.com/
    def initialize(api_key = nil, options = {})
      @api_key = api_key
      @api_key ||= Songkickr.api_key
      @debug = options[:debug] || false

      self.class.default_params apikey: @api_key
      if @debug
        self.class.debug_output $stderr
      end
    end

    def get(location, query_params = {})
      result = self.class.get(location, query_params)
      # FIXME: this is shit. should be based on on http response.
      if result['resultsPage']['error']
        msg = result['resultsPage']['error']['message']
        raise ResourceNotFound if msg =~ /not found/
        raise APIError.new(msg)
      end
      result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
songkickr-0.5.5 lib/songkickr/remote.rb