Class: Bandsintown::Artist
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns an array of Bandsintown::Event objects for each of the artist’s upcoming events available through bandsintown.com.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#upcoming_events_count ⇒ Object
Returns the value of attribute upcoming_events_count.
Attributes inherited from Base
Class Method Summary collapse
- .build_from_json(json_hash) ⇒ Object
-
.get(options = {}) ⇒ Object
Returns a Bandsintown::Artist object with basic information for a single artist, including the number of upcoming events.
- .resource_path ⇒ Object
Instance Method Summary collapse
-
#api_name ⇒ Object
Used in api requests as the RESTful resource id for artists (api.bandsintown.com/artists/id/method).
-
#initialize(options = {}) ⇒ Artist
constructor
A new instance of Artist.
-
#on_tour? ⇒ Boolean
Returns true if there is at least 1 upcoming event for the artist, or false if there are 0 upcoming events for the artist.
Methods inherited from Base
check_for_errors, connection, parse, request, request_and_parse, #to_hash
Constructor Details
#initialize(options = {}) ⇒ Artist
Returns a new instance of Artist.
6 7 8 9 10 |
# File 'lib/bandsintown/artist.rb', line 6 def initialize( = {}) @name = [:name] @mbid = [:mbid] @bandsintown_url = [:url] || build_bandsintown_url end |
Instance Attribute Details
#events ⇒ Object
Returns an array of Bandsintown::Event objects for each of the artist’s upcoming events available through bandsintown.com. See www.bandsintown.com/api/requests#artists-events for more information. Can be used with either artist name or mbid (music brainz id).
example:
# using artist name
artist = Bandsintown::Artist.new(:name => "Little Brother")
upcoming_little_brother_events = artist.events
# using mbid for Little Brother
artist = Bandsintown::Artist.new(:mbid => "b929c0c9-5de0-4d87-8eb9-365ad1725629")
upcoming_little_brother_events = artist.events
24 25 26 |
# File 'lib/bandsintown/artist.rb', line 24 def events @events end |
#mbid ⇒ Object
Returns the value of attribute mbid.
4 5 6 |
# File 'lib/bandsintown/artist.rb', line 4 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bandsintown/artist.rb', line 4 def name @name end |
#upcoming_events_count ⇒ Object
Returns the value of attribute upcoming_events_count.
4 5 6 |
# File 'lib/bandsintown/artist.rb', line 4 def upcoming_events_count @upcoming_events_count end |
Class Method Details
.build_from_json(json_hash) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/bandsintown/artist.rb', line 76 def self.build_from_json(json_hash) returning Bandsintown::Artist.new({}) do |artist| artist.name = json_hash['name'] artist.mbid = json_hash['mbid'] artist.bandsintown_url = json_hash['url'] artist.upcoming_events_count = json_hash['upcoming_events_count'] end end |
.get(options = {}) ⇒ Object
Returns a Bandsintown::Artist object with basic information for a single artist, including the number of upcoming events. Useful in determining if an artist is on tour without requesting the event data. See www.bandsintown.com/api/requests#artists-get for more information. Can be used with either artist name or mbid (music brainz id).
example:
# using artist name
artist = Bandsintown::Artist.get(:name => "Little Brother")
# using mbid for Little Brother
artist = Bandsintown::Artist.get(:mbid => "b929c0c9-5de0-4d87-8eb9-365ad1725629")
71 72 73 74 |
# File 'lib/bandsintown/artist.rb', line 71 def self.get( = {}) request_url = Bandsintown::Artist.new().api_name build_from_json(request_and_parse(:get, request_url)) end |
.resource_path ⇒ Object
85 86 87 |
# File 'lib/bandsintown/artist.rb', line 85 def self.resource_path "artists" end |
Instance Method Details
#api_name ⇒ Object
Used in api requests as the RESTful resource id for artists (api.bandsintown.com/artists/id/method). If @name is not nil, it will be URI escaped to generate the api_name. ‘/’ and ‘?’ must be double escaped. If @name is nil, @mbid is used with ‘mbid_’ prefixed.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bandsintown/artist.rb', line 33 def api_name if @name name = @name.dup name.gsub!('/', CGI.escape('/')) name.gsub!('?', CGI.escape('?')) URI.escape(name) else "mbid_#{@mbid}" end end |
#on_tour? ⇒ Boolean
Returns true if there is at least 1 upcoming event for the artist, or false if there are 0 upcoming events for the artist. Should only be used for artists requested using Bandsintown::Artist.get, or with events already loaded, otherwise an error will be raised.
example:
# using .get method
artist = Bandsintown::Artist.get(:name => "Little Brother")
artist_on_tour = artist.on_tour?
# using .initialize and .events methods
artist = Bandsintown::Artist.get(:name => "Little Brother")
events = artist.events
artist_on_tour = artist.on_tour?
56 57 58 |
# File 'lib/bandsintown/artist.rb', line 56 def on_tour? (@upcoming_events_count || @events.size) > 0 end |