Class: BandsInTownApiClient::Request
- Inherits:
-
Object
- Object
- BandsInTownApiClient::Request
- Defined in:
- lib/bands_in_town_api_client/request.rb
Instance Method Summary collapse
- #action_uri ⇒ Object
- #error_response ⇒ Object
-
#initialize(action, artist_id, client_id, format = :json) ⇒ Request
constructor
A new instance of Request.
- #response ⇒ Object
Constructor Details
#initialize(action, artist_id, client_id, format = :json) ⇒ Request
Returns a new instance of Request.
3 4 5 6 7 8 9 |
# File 'lib/bands_in_town_api_client/request.rb', line 3 def initialize( action, artist_id, client_id, format=:json ) base_url = "http://api.bandsintown.com/" @action = action @artist_id = artist_id get_params = "?api_version=2.0&app_id=#{client_id}" @url = "#{base_url}#{action_uri}.#{format}#{get_params}" end |
Instance Method Details
#action_uri ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/bands_in_town_api_client/request.rb', line 25 def action_uri case @action when :events "artists/#{@artist_id}/events" else raise "Unsuported api action" end end |
#error_response ⇒ Object
21 22 23 |
# File 'lib/bands_in_town_api_client/request.rb', line 21 def error_response { error: @error } end |
#response ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/bands_in_town_api_client/request.rb', line 11 def response begin r = open(@url) JSON::parse(r.read) rescue => e @error = e error_response end end |