Class: Songkicky::Artist

Inherits:
Object
  • Object
show all
Includes:
JsonApi
Defined in:
lib/artist.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonApi

#all

Constructor Details

#initialize(mbid) ⇒ Artist

Returns a new instance of Artist.



25
26
27
28
# File 'lib/artist.rb', line 25

def initialize(mbid)
  @mbid   = mbid
  @upcoming_events = nil
end

Instance Attribute Details

#mbidObject

Returns the value of attribute mbid.



7
8
9
# File 'lib/artist.rb', line 7

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/artist.rb', line 7

def name
  @name
end

Class Method Details

.find_by_mbid(mbid) ⇒ Object

Raises:



10
11
12
13
14
# File 'lib/artist.rb', line 10

def find_by_mbid(mbid)
  raise Error.new("MusicBrainz id is blank") if mbid.nil? || mbid.strip == ''

  Artist.new(mbid)
end

.find_by_name(name) ⇒ Object

Raises:



16
17
18
19
20
21
22
# File 'lib/artist.rb', line 16

def find_by_name(name)
  raise Error.new("Name is blank") if name.nil? || name.strip == ''

  a = Artist.new(nil)
  a.name = name
  a
end

Instance Method Details

#upcoming_eventsObject



30
31
32
33
34
35
# File 'lib/artist.rb', line 30

def upcoming_events
  return @upcoming_events if @upcoming_events

  events_hash = all("artists/mbid:#{@mbid}/events.json", 'event')
  @upcoming_events = events_hash.map {|hash| Event.new(hash) }
end