Class: Scrobbler::Event

Inherits:
Base
  • Object
show all
Extended by:
ImageClassFuncs
Includes:
ImageObjectFuncs
Defined in:
lib/scrobbler/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ImageClassFuncs

maybe_image_node

Methods included from ImageObjectFuncs

#check_image_node, #image

Methods inherited from Base

api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=

Constructor Details

#initialize(id, input = {}) ⇒ Event

Returns a new instance of Event.

Raises:

  • (ArgumentError)


66
67
68
69
70
71
# File 'lib/scrobbler/event.rb', line 66

def initialize(id,input={})
  raise ArgumentError if id.blank?
  @id = id
  populate_data(input)
  load_info() if input[:include_info]
end

Instance Attribute Details

#artistsObject

Returns the value of attribute artists.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def artists
  @artists
end

#attendanceObject

Returns the value of attribute attendance.



9
10
11
# File 'lib/scrobbler/event.rb', line 9

def attendance
  @attendance
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#headlinerObject

Returns the value of attribute headliner.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def headliner
  @headliner
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#image_largeObject

Returns the value of attribute image_large.



9
10
11
# File 'lib/scrobbler/event.rb', line 9

def image_large
  @image_large
end

#image_mediumObject

Returns the value of attribute image_medium.



9
10
11
# File 'lib/scrobbler/event.rb', line 9

def image_medium
  @image_medium
end

#image_smallObject

Returns the value of attribute image_small.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def image_small
  @image_small
end

#reviewsObject

Returns the value of attribute reviews.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def reviews
  @reviews
end

#start_dateObject

Returns the value of attribute start_date.



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

def start_date
  @start_date
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#tagObject

Returns the value of attribute tag.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def tag
  @tag
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/scrobbler/event.rb', line 8

def url
  @url
end

#venueObject

Returns the value of attribute venue.



9
10
11
# File 'lib/scrobbler/event.rb', line 9

def venue
  @venue
end

Class Method Details

.headliner_alrady_listed_in_artist_list?(artists, headliner) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/scrobbler/event.rb', line 54

def headliner_alrady_listed_in_artist_list?(artists,headliner)
  artists.each do |artist|
    return true if artist.name == headliner.name
  end
  false
end

.new_from_libxml(xml) ⇒ Object



61
62
63
# File 'lib/scrobbler/event.rb', line 61

def new_from_libxml(xml)
  update_or_create_from_xml(xml)
end

.update_or_create_from_xml(xml, event = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/scrobbler/event.rb', line 13

def update_or_create_from_xml(xml, event=nil)
  data = {}
  artists = []
  headliner = nil
  venue = nil

  xml.children.each do |child|
    data[:id] = child.content.to_i if child.name == 'id'
    data[:title] = child.content if child.name == 'title'

    if child.name == 'artists'
      child.children.each do |artist_element|
        artists << Artist.new(artist_element.content) if artist_element.name == 'artist'
        headliner = Artist.new(artist_element.content) if artist_element.name == 'headliner'
      end
      artists << headliner unless headliner.nil? || headliner_alrady_listed_in_artist_list?(artists,headliner)
    end

    maybe_image_node(data, child)
    data[:url] = child.content if child.name == 'url'
    data[:description] = child.content if child.name == 'description'
    data[:attendance] = child.content.to_i if child.name == 'attendance'
    data[:reviews]    = child.content.to_i if child.name == 'reviews'
    data[:tag]        = child.content if child.name == 'tag'
    data[:start_date] = Time.parse(child.content) if child.name == 'startDate'
    data[:start_time] = child.content if child.name == 'startTime'
    venue = Venue.new_from_xml(child) if child.name == 'venue'
  end

  if event.nil?
    event = Event.new(data[:id],data)
  else
    event.send :populate_data, data
  end

  event.artists = artists.uniq
  event.headliner = headliner
  event.venue = venue
  event
end

Instance Method Details

#attend(session, attendance_status) ⇒ Object



86
87
88
# File 'lib/scrobbler/event.rb', line 86

def attend(session, attendance_status)
  doc = Base.post_request('event.attend',{:event => @id, :signed => true, :status => attendance_status, :sk => session.key})
end

#attendees(force = false) ⇒ Object



77
78
79
# File 'lib/scrobbler/event.rb', line 77

def attendees(force = false)
  get_response('event.getattendees', :attendees, 'attendees', 'user', {'event'=>@id}, force)
end

#load_infoObject

Load additional informatalbumion about this event

Calls “event.getinfo” REST method



98
99
100
101
102
103
# File 'lib/scrobbler/event.rb', line 98

def load_info
  doc = Base.request('event.getinfo', {'event' => @id})
  doc.root.children.each do |child|        
    Event.update_or_create_from_xml(child, self) if child.name == 'event'
  end      
end

#shareObject

Raises:

  • (NotImplementedError)


90
91
92
93
# File 'lib/scrobbler/event.rb', line 90

def share
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

#shoutObject

Raises:

  • (NotImplementedError)


81
82
83
84
# File 'lib/scrobbler/event.rb', line 81

def shout
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

#shouts(force = false) ⇒ Object



73
74
75
# File 'lib/scrobbler/event.rb', line 73

def shouts(force = false)
  get_response('event.getshouts', :shouts, 'shouts', 'shout', {'event'=>@id}, force)
end