Class: Scrobbler::Venue

Inherits:
Base
  • Object
show all
Defined in:
lib/scrobbler/venue.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(name, data = {}) ⇒ Venue

Returns a new instance of Venue.

Raises:

  • (ArgumentError)


53
54
55
56
57
# File 'lib/scrobbler/venue.rb', line 53

def initialize(name,data = {})
  raise ArgumentError if name.blank?
  @name = name
  populate_data(data)
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/scrobbler/venue.rb', line 3

def city
  @city
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/scrobbler/venue.rb', line 3

def country
  @country
end

#geo_latObject

Returns the value of attribute geo_lat.



4
5
6
# File 'lib/scrobbler/venue.rb', line 4

def geo_lat
  @geo_lat
end

#geo_longObject

Returns the value of attribute geo_long.



4
5
6
# File 'lib/scrobbler/venue.rb', line 4

def geo_long
  @geo_long
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/scrobbler/venue.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/scrobbler/venue.rb', line 3

def name
  @name
end

#postalcodeObject

Returns the value of attribute postalcode.



3
4
5
# File 'lib/scrobbler/venue.rb', line 3

def postalcode
  @postalcode
end

#streetObject

Returns the value of attribute street.



3
4
5
# File 'lib/scrobbler/venue.rb', line 3

def street
  @street
end

#timezoneObject

Returns the value of attribute timezone.



4
5
6
# File 'lib/scrobbler/venue.rb', line 4

def timezone
  @timezone
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/scrobbler/venue.rb', line 4

def url
  @url
end

Class Method Details

.id_from_url(url) ⇒ Object

this retrives the venue ID from the venue because the venue ID is not supplied in the XML apart from in the venue URL



44
45
46
# File 'lib/scrobbler/venue.rb', line 44

def id_from_url(url)
  url[url.rindex('/')+1,url.length].to_i
end

.new_from_xml(xml) ⇒ Object



7
8
9
10
11
12
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
# File 'lib/scrobbler/venue.rb', line 7

def new_from_xml(xml)
  data = {}
  xml.children.each do |child|
    data[:name] = child.content if child.name == 'name'
    data[:id] = child.content.to_i if child.name == 'id'
    data[:url] = child.content if child.name == 'url'          

    if child.name == 'location'
      child.children.each do |location_element|
        data[:city] = location_element.content if location_element.name == 'city'
        data[:country] = location_element.content if location_element.name == 'country'
        data[:street] = location_element.content if location_element.name == 'street'
        data[:postalcode] = location_element.content if location_element.name == 'postalcode'
        data[:timezone] = location_element.content if location_element.name == 'timezone'

        if location_element.name == 'point' || location_element.name == 'geo:point'
          location_element.children.each do |geo_element|
            data[:geo_lat] = geo_element.content if ['lat', 'geo:lat'].include?(geo_element.name)
            data[:geo_long] = geo_element.content if ['long', 'geo:long'].include?(geo_element.name)
          end
        end
      end
    end
  end

  if data.has_key?(:url) && !data.has_key?(:id)
    data[:id] = id_from_url(data[:url])
  end

  Venue.new(data[:name], data)
end

.search(venue, force = false) ⇒ Object



48
49
50
# File 'lib/scrobbler/venue.rb', line 48

def search(venue, force=false)
  get_response('venue.search', :venuematches, 'venuematches', 'venue', {'venue'=>venue}, force)
end

Instance Method Details

#events(force = false) ⇒ Object



59
60
61
# File 'lib/scrobbler/venue.rb', line 59

def events(force=false)
  get_response('venue.getevents', :events, 'events', 'event', {'venue'=>@id}, force)
end

#past_events(force = false) ⇒ Object



63
64
65
# File 'lib/scrobbler/venue.rb', line 63

def past_events(force=false)
  get_response('venue.getpastevents', :events, 'events', 'event', {'venue'=>@id}, force)
end