Sha256: fdaf1039b847ec6a63c090c201b1745842cc264254d2d3f8b6e06ca5595168fe

Contents?: true

Size: 1.43 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
songkickr-0.5.4 lib/songkickr/remote.rb
songkickr-0.5.3 lib/songkickr/remote.rb
songkickr-0.5.2 lib/songkickr/remote.rb
songkickr-0.5.0 lib/songkickr/remote.rb
songkickr-0.4.1 lib/songkickr/remote.rb
songkickr-0.4.0 lib/songkickr/remote.rb