eostrom-zvent 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +41 -0
- data/lib/core/ext.rb +18 -0
- data/lib/zvent.rb +11 -0
- data/lib/zvent/base.rb +40 -0
- data/lib/zvent/category.rb +14 -0
- data/lib/zvent/event.rb +131 -0
- data/lib/zvent/performer.rb +28 -0
- data/lib/zvent/session.rb +302 -0
- data/lib/zvent/venue.rb +31 -0
- metadata +82 -0
data/README
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= Zvent 0.0.3
|
2
|
+
|
3
|
+
An interface with zvents API without all the mess.
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
An interface with zvents API without all the mess.
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
give it your API key when you initialize the session object.
|
12
|
+
@zvent = Zvent::Sesion.new('API_KEY')
|
13
|
+
|
14
|
+
To get an event you give it an event id.
|
15
|
+
This call returns an event object.
|
16
|
+
event = @zvent.find_event('12345')
|
17
|
+
|
18
|
+
The event can get images of all different types and sizes
|
19
|
+
event.image('tiny') # returns an image (44x44)
|
20
|
+
|
21
|
+
The event can have categories of sorts
|
22
|
+
event.categories # returns the category object
|
23
|
+
|
24
|
+
The event has support for timezones. Please read the rdoc for more examples
|
25
|
+
event.startTime # Returns the UTC of the start time
|
26
|
+
event.endTime(false) # Returns the end time of the event in local time to the venue.
|
27
|
+
# If the venue is in US/Pacific the time of the event will come back
|
28
|
+
# in US/Pacific.
|
29
|
+
|
30
|
+
Each event has a venue object
|
31
|
+
venue = event.venue # returns the venue object
|
32
|
+
|
33
|
+
To search for events give it a location
|
34
|
+
events = @zvent.find_events('Simi Valley, CA')
|
35
|
+
events[:event_count] # how many events total are in this search
|
36
|
+
events[:events] # access to the array of events
|
37
|
+
|
38
|
+
== TODO
|
39
|
+
|
40
|
+
- Improve the documentation
|
41
|
+
- Ensure the classes don't blow up when you start asking for specific things
|
data/lib/core/ext.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# backported from rails
|
2
|
+
class Hash
|
3
|
+
def to_query(namespace = nil)
|
4
|
+
collect do |key, value|
|
5
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
6
|
+
end.sort * '&'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Object
|
11
|
+
def to_query(key)
|
12
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_param
|
16
|
+
to_s
|
17
|
+
end
|
18
|
+
end
|
data/lib/zvent.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'json'
|
7
|
+
require 'tzinfo'
|
8
|
+
require 'cgi'
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
Dir[File.dirname(__FILE__) + "/zvent/*.rb"].each { |file| require(file) }
|
data/lib/zvent/base.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Zvent
|
2
|
+
# raised when no location is given when it is required
|
3
|
+
class NoLocationError < StandardError; end
|
4
|
+
|
5
|
+
# raised when no id proveded when it is required
|
6
|
+
class NoIdError < StandardError; end
|
7
|
+
|
8
|
+
# raise when not given an API key
|
9
|
+
class NoApiKeyError < StandardError; end
|
10
|
+
|
11
|
+
# raise when the API doesn't like the request
|
12
|
+
class ZventApiError < StandardError; end
|
13
|
+
|
14
|
+
# Raise when the API returns a failure
|
15
|
+
class ZventApiFailure < StandardError ; end
|
16
|
+
|
17
|
+
# Raises when asking for an invalid image size
|
18
|
+
class InvalidImageSize < StandardError; end
|
19
|
+
|
20
|
+
class Base
|
21
|
+
|
22
|
+
# Get Json and parse it
|
23
|
+
def get_resources(url)
|
24
|
+
url = URI.parse(url)
|
25
|
+
|
26
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
27
|
+
http.get(url.request_uri+"&format=json&key=#{@api_key}")
|
28
|
+
}
|
29
|
+
resources = JSON.parse(res.body)
|
30
|
+
|
31
|
+
if resources['rsp']['status'] == 'error'
|
32
|
+
raise Zvent::ZventApiError.new(resources['rsp']['msg'])
|
33
|
+
elsif resources['rsp']['status'] == 'failed'
|
34
|
+
raise Zvent::ZventApiFailure.new(resources['rsp']['msg'])
|
35
|
+
end
|
36
|
+
|
37
|
+
return resources
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Zvent
|
2
|
+
# An object that represents a single venue from zvents
|
3
|
+
class Category < Base
|
4
|
+
attr_accessor :name, :pid, :id, :count
|
5
|
+
|
6
|
+
def initialize(category_hash)
|
7
|
+
begin
|
8
|
+
category_hash.each_pair{|key, value| self.send("#{key}=", value) }
|
9
|
+
rescue NoMethodError => e
|
10
|
+
# Do nothing!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/zvent/event.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
module Zvent
|
2
|
+
# An object that represents a single event from zvents
|
3
|
+
class Event < Base
|
4
|
+
IMAGE_SIZES = ['tiny', 'medium', 'featured', 'primary', 'original']
|
5
|
+
|
6
|
+
attr_accessor :name, :artists, :price, :private, :editors_pick, :url, :approved,
|
7
|
+
:sc, :id, :images, :description, :vid, :color, :phone, :startTime,
|
8
|
+
:endTime, :zurl, :venue, :categories, :age_suitability
|
9
|
+
|
10
|
+
# expects the json hash that is given from zvents
|
11
|
+
def initialize(event_hash)
|
12
|
+
event_hash.each_pair do |key, value|
|
13
|
+
begin
|
14
|
+
self.send("#{key}=", value)
|
15
|
+
rescue NoMethodError => e
|
16
|
+
#do nothing
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Zvents Partner API
|
21
|
+
self.url ||= event_hash['link']
|
22
|
+
self.startTime ||= event_hash['starttime']
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get the start time of the event. Events are guaranteed an start time.
|
26
|
+
# The function will return a DateTime object of the time.
|
27
|
+
#
|
28
|
+
# <b>options</b>
|
29
|
+
# <tt>utc</tt> - Want the time in local (to the venue) or in UTC? Defaults to UTC
|
30
|
+
def startTime(utc=true)
|
31
|
+
# if there is no startTime return nil
|
32
|
+
return nil if @startTime.nil?
|
33
|
+
|
34
|
+
# Parse the startTime
|
35
|
+
start_time = DateTime.parse(@startTime)
|
36
|
+
|
37
|
+
# Decide if we need to return UTC or local time
|
38
|
+
utc ? DateTime.parse(self.tz_timezone.local_to_utc(start_time).to_s) : start_time
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get the end time of the event. Events are not guaranteed an end time.
|
42
|
+
# The function will return a DateTime object of the time. If there isn't an endtime it will return nil.
|
43
|
+
#
|
44
|
+
# <b>options</b>
|
45
|
+
# <tt>utc</tt> - Want the time in local (to the venue) or in UTC? Defaults to UTC
|
46
|
+
def endTime(utc=true)
|
47
|
+
# if there is no startTime return nil
|
48
|
+
return nil if @endTime.nil?
|
49
|
+
|
50
|
+
# Parse the startTime
|
51
|
+
end_time = DateTime.parse(@endTime)
|
52
|
+
|
53
|
+
# Decide if we need to return UTC or local time
|
54
|
+
utc ? DateTime.parse(self.tz_timezone.local_to_utc(end_time).to_s) : end_time
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the tz timezone object from the venue
|
58
|
+
def tz_timezone ; @venue.tz_timezone; end
|
59
|
+
|
60
|
+
# Does the event have any images
|
61
|
+
def images? ; !(@images.nil? || @images.empty?); end
|
62
|
+
|
63
|
+
# Does the event or venue have any images
|
64
|
+
def deep_images?
|
65
|
+
self.images? || (@venue.nil? ? false : @venue.images?)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Categories takes in some json
|
69
|
+
def categories=(categories_json)
|
70
|
+
categories_json.each do |category|
|
71
|
+
if @categories.nil?
|
72
|
+
@categories = [Zvent::Category.new(category)]
|
73
|
+
else
|
74
|
+
@categories << Zvent::Category.new(category)
|
75
|
+
end
|
76
|
+
end if categories_json
|
77
|
+
end
|
78
|
+
|
79
|
+
# Does the event have any categories attached to it?
|
80
|
+
def category? ; !(@categories.nil? || @categories.empty?) ; end
|
81
|
+
|
82
|
+
# Returns the first image it sees from event. If none is found it will return nil
|
83
|
+
# <b>size</b>
|
84
|
+
# * <tt>tiny</tt> - 44x44
|
85
|
+
# * <tt>medium</tt> - 66x66
|
86
|
+
# * <tt>featured</tt> - 150x150
|
87
|
+
# * <tt>primary</tt> - 184x184
|
88
|
+
# * <tt>original</tt> Will just grab the original image from zvents (default)
|
89
|
+
def image(size='original')
|
90
|
+
self.images? ? convert_image(@images.first, size) : nil
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the first image it sees. First it checks the event for images thent the venue for images.
|
94
|
+
# If none is found it will return nil
|
95
|
+
#
|
96
|
+
# <b>size</b>
|
97
|
+
# * <tt>tiny</tt> - 44x44
|
98
|
+
# * <tt>medium</tt> - 66x66
|
99
|
+
# * <tt>featured</tt> - 150x150
|
100
|
+
# * <tt>primary</tt> - 184x184
|
101
|
+
# * <tt>original</tt> Will just grab the original image from zvents (default)
|
102
|
+
def deep_image(size='original')
|
103
|
+
image = nil
|
104
|
+
if self.images?
|
105
|
+
image = @images.first
|
106
|
+
elsif self.venue
|
107
|
+
image = @venue.images? ? @venue.images.first : nil
|
108
|
+
else
|
109
|
+
image = nil
|
110
|
+
end
|
111
|
+
|
112
|
+
(image.nil?) ? image : convert_image(image, size)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Checks to see if the event has a venue
|
116
|
+
def venue? ; !(@venue.nil?) ; end
|
117
|
+
|
118
|
+
private
|
119
|
+
# grab the size of the image requested
|
120
|
+
def convert_image(image, size)
|
121
|
+
# Apparently venue returns a different kind of image than event.
|
122
|
+
image_url = image.kind_of?(Hash) ? image['url'] : image
|
123
|
+
|
124
|
+
# if the size is original just return the image
|
125
|
+
return image_url if size == 'original'
|
126
|
+
|
127
|
+
# else grab the specific size
|
128
|
+
IMAGE_SIZES.include?(size) ? image_url.insert(image_url.index('.jpg'), "_#{size}") : (raise Zvent::InvalidImageSize.new)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Zvent
|
2
|
+
# An object that represents a single venue from zvents
|
3
|
+
class Performer < Base
|
4
|
+
attr_accessor :name, :url, :id, :images, :description, :zurl
|
5
|
+
|
6
|
+
def initialize(performer_hash)
|
7
|
+
performer_hash.each_pair do |key, value|
|
8
|
+
begin
|
9
|
+
self.send("#{key}=", value)
|
10
|
+
rescue NoMethodError => e
|
11
|
+
#do nothing
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Zvents Partner API
|
16
|
+
self.url ||= performer_hash['link']
|
17
|
+
self.description ||= performer_hash['summary']
|
18
|
+
end
|
19
|
+
|
20
|
+
# Does the performer have any images
|
21
|
+
def images? ; !(@images.nil? || @images.empty?) ; end
|
22
|
+
|
23
|
+
def timezone? ; !(@timezone.nil? || @timezone.empty?) ; end
|
24
|
+
|
25
|
+
# Returns the tz timezone object
|
26
|
+
def tz_timezone ; timezone? ? TZInfo::Timezone.get(@timezone) : nil ; end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
module Zvent
|
2
|
+
# A zvent session used to search and everything
|
3
|
+
class Session < Base
|
4
|
+
DEFAULT_BASE_URL = "http://www.zvents.com/rest"
|
5
|
+
|
6
|
+
# Default zvents arguments
|
7
|
+
# Image_size = none assures we just get the plain file name. Transformations to different sizes are done within the gem
|
8
|
+
ZVENTS_DEFAULT_ARGUMENTS = {:image_size => 'none'}
|
9
|
+
|
10
|
+
# Initializes the session object. It requires an API key
|
11
|
+
def initialize(api_key, options = {})
|
12
|
+
raise Zvent::NoApiKeyError.new if !api_key || api_key.strip.empty?
|
13
|
+
@api_key = api_key
|
14
|
+
@base_url = options[:base_url] || DEFAULT_BASE_URL
|
15
|
+
end
|
16
|
+
|
17
|
+
# Use this method to find events from zvents.
|
18
|
+
#
|
19
|
+
# <b>Return</b>
|
20
|
+
# returns a hash that contains an array of events and an event count
|
21
|
+
# {:event_count => 10, :events => [<# event>, ...]}
|
22
|
+
#
|
23
|
+
# <b>Arguments</b>
|
24
|
+
#
|
25
|
+
# location
|
26
|
+
# * <tt>location</tt> - A string describing a location around which the search results will be restricted. (e.g., san francisco, ca or 94131). You can also specify a location using a longitude/latitude coordinate pair using the notation -74.0:BY:40.9
|
27
|
+
#
|
28
|
+
# zvent_options
|
29
|
+
# * <tt>what</tt> - The string against which events are matched. (e.g., parade). (<tt>default</tt> = nil, which searches for everything)
|
30
|
+
# * <tt>when</tt> - A string specifying a date range for the search (e.g., today, this week, next week, friday, etc.). Explicit date ranges can be specified by separating two dates with the word "to" (e.g., monday to thursday, 10/30/2007 to 11/4/2007). Leave this string blank to search all future events.
|
31
|
+
# * <tt>radius</tt> - The number of miles around the location (specified in the where field) to search. If this field is left blank, a default radius is supplied. The default radius varies according to the location specified in the where field.
|
32
|
+
# * <tt>limit</tt> - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(<tt>Default</tt> = 10. <tt>Max</tt> = 25)
|
33
|
+
# * <tt>offset</tt> - The number of events to skip from the beginning of the search results. If a search matches 1000 events, returning 25 events starting at offset 100 will return event numbers 100-125 that match the search. (<tt>Default</tt> = 0)
|
34
|
+
# * <tt>trim</tt> - Set to 1 if repeating events should be trimmed from the search results. Set to 0 to return repeating events. If the trim option is enabled, only 1 event will be returned from each repeating series that matches the search. The number of events within the series that match the search is returned in the series_count response parameter. Defaults to 1.
|
35
|
+
# * <tt>sort</tt> - Set to 1 to sort search results by start time. Set to 0 to sort search results by relevance. Defaults to 0.
|
36
|
+
# * <tt>cat</tt> - Restrict your search to items that belong to a specific category. You must provide a category identifier which can be determined using the categories API call.
|
37
|
+
# * <tt>catex</tt> - Exclude items from a specific category from the search. You must provide a category identifier which can be determined using the categories API call.
|
38
|
+
#
|
39
|
+
# options
|
40
|
+
# * <tt>as_json</tt> - If set to true method will return the json from zvents without any transformation. (<tt>false</tt> by default).
|
41
|
+
#
|
42
|
+
# Examples:
|
43
|
+
# find_events('93063')
|
44
|
+
# => Finds any 10 events near the 93063 zip code area.
|
45
|
+
#
|
46
|
+
# find_events('611 N. Brand Blvd. Glendale, Ca', {:what => 'dancing', :limit => 25})
|
47
|
+
# => Finds 25 events near the address that consists of dancing
|
48
|
+
#
|
49
|
+
# find_events('611 N. Brand Blvd. Glendale, Ca', {:what => 'dancing'}, {:as_json => true})
|
50
|
+
# => Should return the json straight from zvents
|
51
|
+
#
|
52
|
+
def find_events(location, zvent_options = {}, options = {})
|
53
|
+
#location is required
|
54
|
+
raise Zvent::NoLocationError.new if !location || location.strip.empty?
|
55
|
+
|
56
|
+
#grab the json from zvents
|
57
|
+
json_ret = get_resources(@base_url+"/search?#{zvent_options.merge(:where => location).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
58
|
+
|
59
|
+
#return the json or objectified json
|
60
|
+
options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Use this method to return a single event from zvents
|
64
|
+
#
|
65
|
+
# <b>Return</b>
|
66
|
+
# returns an single event. If an event can not be found it will return nil
|
67
|
+
# <# event>
|
68
|
+
#
|
69
|
+
# <b>Arguments</b>
|
70
|
+
# event_id
|
71
|
+
# * <tt>id</tt> - ID of the event
|
72
|
+
#
|
73
|
+
# options
|
74
|
+
# * <tt>as_json</tt> - If set to true method will return the json from zvents without any transformation. (<tt>false</tt> by default).
|
75
|
+
#
|
76
|
+
# Examples:
|
77
|
+
# find_event('1234')
|
78
|
+
# => Finds an event with the id of 1234
|
79
|
+
#
|
80
|
+
# find_event('1234', {:as_json => true})
|
81
|
+
# => Finds an event with the id of 1234 and returns the json as it comes in from zvents
|
82
|
+
def find_event(event_id, zvent_options={}, options = {})
|
83
|
+
# event_id is required
|
84
|
+
raise Zvent::NoIdError if event_id.strip.empty?
|
85
|
+
|
86
|
+
#grab the json from zvents
|
87
|
+
json_ret = get_resources(@base_url+"/event?#{zvent_options.merge(:id => event_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
88
|
+
|
89
|
+
#return the json or objectified json
|
90
|
+
options[:as_json] ? json_ret : objectify_zvents_json(json_ret)[:events].first
|
91
|
+
end
|
92
|
+
|
93
|
+
# Use this method to find venues from zvents.
|
94
|
+
#
|
95
|
+
# <b>Return</b>
|
96
|
+
# returns a hash that contains an array of venues and a venue count
|
97
|
+
# {:venue_count => 10, :venues => [<# venue>, ...]}
|
98
|
+
#
|
99
|
+
# <b>Arguments</b>
|
100
|
+
#
|
101
|
+
# location
|
102
|
+
# * <tt>location</tt> - A string describing a location around which the search results will be restricted. (e.g., san francisco, ca or 94131). You can also specify a location using a longitude/latitude coordinate pair using the notation -74.0:BY:40.9
|
103
|
+
#
|
104
|
+
# zvent_options
|
105
|
+
# * <tt>what</tt> - The string against which venues are matched. (e.g., parade). (<tt>default</tt> = nil, which searches for everything)
|
106
|
+
# * <tt>radius</tt> - The number of miles around the location (specified in the where field) to search. If this field is left blank, a default radius is supplied. The default radius varies according to the location specified in the where field.
|
107
|
+
# * <tt>limit</tt> - The maximum number of matching venues to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(<tt>Default</tt> = 10. <tt>Max</tt> = 25)
|
108
|
+
# * <tt>offset</tt> - The number of venues to skip from the beginning of the search results. If a search matches 1000 venues, returning 25 venues starting at offset 100 will return venue numbers 100-125 that match the search. (<tt>Default</tt> = 0)
|
109
|
+
# * <tt>vt</tt> - Restrict your search to items that belong to a specific venue type. You must provide a venue type id.
|
110
|
+
#
|
111
|
+
# options
|
112
|
+
# * <tt>as_json</tt> - If set to true method will return the json from zvents without any transformation. (<tt>false</tt> by default).
|
113
|
+
#
|
114
|
+
# Examples:
|
115
|
+
# find_venues('93063')
|
116
|
+
# => Finds any 10 venues near the 93063 zip code area.
|
117
|
+
#
|
118
|
+
# find_venues('611 N. Brand Blvd. Glendale, Ca', {:what => 'museum', :limit => 25})
|
119
|
+
# => Finds 25 venues near the address that match 'museum'
|
120
|
+
#
|
121
|
+
# find_venues('611 N. Brand Blvd. Glendale, Ca', {:what => 'museum'}, {:as_json => true})
|
122
|
+
# => Should return the json straight from zvents
|
123
|
+
#
|
124
|
+
def find_venues(location, zvent_options = {}, options = {})
|
125
|
+
#location is required
|
126
|
+
raise Zvent::NoLocationError.new if !location || location.strip.empty?
|
127
|
+
|
128
|
+
#grab the json from zvents
|
129
|
+
json_ret = get_resources(@base_url+"/search_for_venues?#{zvent_options.merge(:where => location).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
130
|
+
|
131
|
+
#return the json or objectified json
|
132
|
+
options[:as_json] ? json_ret : objectify_venues_json(json_ret)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Use this method to find events at a given venue from zvents.
|
136
|
+
#
|
137
|
+
# <b>Return</b>
|
138
|
+
# returns a hash that contains an array of events and an event count
|
139
|
+
# {:event_count => 10, :events => [<# event>, ...]}
|
140
|
+
#
|
141
|
+
# <b>Arguments</b>
|
142
|
+
#
|
143
|
+
# venue_id
|
144
|
+
# * <tt>venue_id</tt> - ID of the venue, gleaned from an earlier Zvents call
|
145
|
+
#
|
146
|
+
# zvent_options
|
147
|
+
# * <tt>limit</tt> - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(<tt>Default</tt> = 10. <tt>Max</tt> = 25)
|
148
|
+
# * <tt>offset</tt> - The number of events to skip from the beginning of the search results. If a search matches 1000 events, returning 25 events starting at offset 100 will return event numbers 100-125 that match the search. (<tt>Default</tt> = 0)
|
149
|
+
# * <tt>sd</tt> - Return only events that start on or after this date. (format: MM/DD/YYYY, defaults to today)
|
150
|
+
# * <tt>ed</tt> - Return only events that start on or before this date. This parameter can be used in conjunction with sd to return events within a specific date range. (format: MM/DD/YYYY)
|
151
|
+
# * <tt>st</tt> - Return only events that start at or after this time. (format: seconds since the epoch, e.g., 1142399089)
|
152
|
+
# * <tt>et</tt> - Return only events that start at or before this time. This parameter can be used in conjunction with st to return events within a specific time range. (format: seconds since the epoch, e.g., 1142399089)
|
153
|
+
#
|
154
|
+
# options
|
155
|
+
# * <tt>as_json</tt> - If set to true method will return the json from zvents without any transformation. (<tt>false</tt> by default).
|
156
|
+
#
|
157
|
+
# Examples:
|
158
|
+
# venue_events(9955)
|
159
|
+
# => Finds any 10 events for venue ID 9955
|
160
|
+
#
|
161
|
+
# venue_events(venue.id)
|
162
|
+
# => Finds any 10 events for the given Zvents::Venue
|
163
|
+
#
|
164
|
+
# venue_events(venue.id, {:sd => '12/31/2009'}, {:as_json => true})
|
165
|
+
# => Finds events starting on New Year's Eve, and returns json
|
166
|
+
def venue_events(venue_id, zvent_options = {}, options = {})
|
167
|
+
venue_id = venue_id.to_i
|
168
|
+
raise Zvent::NoLocationError.new if venue_id == 0
|
169
|
+
|
170
|
+
#grab the json from zvents
|
171
|
+
json_ret = get_resources(@base_url+"/venue_events?#{zvent_options.merge(:id => venue_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
172
|
+
|
173
|
+
#return the json or objectified json
|
174
|
+
options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Use this method to find performers from zvents.
|
178
|
+
#
|
179
|
+
# <b>Return</b>
|
180
|
+
# returns a hash that contains an array of performers and a performer count
|
181
|
+
# {:performer_count => 10, :performers => [<# performer>, ...]}
|
182
|
+
#
|
183
|
+
# <b>Arguments</b>
|
184
|
+
#
|
185
|
+
# what
|
186
|
+
# * <tt>what</tt> - The string against which items are matched in the search. (e.g., parade).
|
187
|
+
#
|
188
|
+
# zvent_options
|
189
|
+
# * <tt>limit</tt> - The maximum number of matching performers to return.
|
190
|
+
#
|
191
|
+
# Examples:
|
192
|
+
# find_performers('Cirque du Soleil')
|
193
|
+
# => Finds any 10 performers matching Cirque du Soleil
|
194
|
+
#
|
195
|
+
# find_performers('Cirque du Soleil', :limit => 1)
|
196
|
+
# => Finds any 1 performer matching Cirque du Soleil
|
197
|
+
#
|
198
|
+
# find_performers('Cirque du Soleil', {:as_json => true})
|
199
|
+
# => Finds performers and returns the result as JSON
|
200
|
+
def find_performers(what, zvent_options = {}, options = {})
|
201
|
+
#grab the json from zvents
|
202
|
+
json_ret = get_resources(@base_url+"/search_for_performers?#{zvent_options.merge(:what => what).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
203
|
+
|
204
|
+
#return the json or objectified json
|
205
|
+
options[:as_json] ? json_ret : objectify_performers_json(json_ret)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Use this method to find events for a given performer from zvents.
|
209
|
+
#
|
210
|
+
# <b>Return</b>
|
211
|
+
# returns a hash that contains an array of events and an event count
|
212
|
+
# {:event_count => 10, :events => [<# event>, ...]}
|
213
|
+
#
|
214
|
+
# <b>Arguments</b>
|
215
|
+
#
|
216
|
+
# performer_id
|
217
|
+
# * <tt>performer_id</tt> - ID of the performer, gleaned from an earlier Zvents call
|
218
|
+
#
|
219
|
+
# zvent_options
|
220
|
+
# * <tt>limit</tt> - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(<tt>Default</tt> = 10. <tt>Max</tt> = 25)
|
221
|
+
# * <tt>when</tt> - A string specifying a date range for the search (e.g., today, this week, next week, friday, etc.). Explicit date ranges can be specified by separating two dates with the word "to" (e.g., monday to thursday, 10/30/2007 to 11/4/2007). Leave this string blank to search all future events.
|
222
|
+
#
|
223
|
+
# options
|
224
|
+
# * <tt>as_json</tt> - If set to true method will return the json from zvents without any transformation. (<tt>false</tt> by default).
|
225
|
+
#
|
226
|
+
# Examples:
|
227
|
+
# performer_events(9955)
|
228
|
+
# => Finds any 10 events for performer ID 9955
|
229
|
+
#
|
230
|
+
# performer_events(performer.id)
|
231
|
+
# => Finds any 10 events for the given Zvents::Performer
|
232
|
+
#
|
233
|
+
# performer_events(performer.id, {:sd => '12/31/2009'}, {:as_json => true})
|
234
|
+
# => Finds events starting on New Year's Eve, and returns json
|
235
|
+
def performer_events(performer_id, zvent_options = {}, options = {})
|
236
|
+
performer_id = performer_id.to_i
|
237
|
+
raise Zvent::NoLocationError.new if performer_id == 0
|
238
|
+
|
239
|
+
#grab the json from zvents
|
240
|
+
json_ret = get_resources(@base_url+"/performer_events?#{zvent_options.merge(:id => performer_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")
|
241
|
+
|
242
|
+
#return the json or objectified json
|
243
|
+
options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
|
244
|
+
end
|
245
|
+
|
246
|
+
protected
|
247
|
+
def objectify_zvents_json(json)
|
248
|
+
venues = objectify_venues(json['rsp']['content']['venues'])
|
249
|
+
{:events => objectify_events(json['rsp']['content']['events'], venues),
|
250
|
+
:event_count => json['rsp']['content']['event_count']||0}
|
251
|
+
end
|
252
|
+
|
253
|
+
def objectify_venues_json(json)
|
254
|
+
{:venues => objectify_venues(json['rsp']['content']['venues']).values,
|
255
|
+
:venue_count => json['rsp']['content']['venue_count']||0}
|
256
|
+
end
|
257
|
+
|
258
|
+
def objectify_performers_json(json)
|
259
|
+
{:performers => objectify_performers(
|
260
|
+
json['rsp']['content']['groups']).values,
|
261
|
+
:performer_count => json['rsp']['content']['group_count']||0}
|
262
|
+
end
|
263
|
+
|
264
|
+
# returns a hash of venues
|
265
|
+
# {venue_id => <# venue >, ...}
|
266
|
+
def objectify_venues(venues)
|
267
|
+
venue_hash = {}
|
268
|
+
venues.each do |venue|
|
269
|
+
v = objectify_venue(venue)
|
270
|
+
venue_hash[v.id] = v
|
271
|
+
end if venues && !venues.empty?
|
272
|
+
venue_hash
|
273
|
+
end
|
274
|
+
|
275
|
+
# returns a hash of performers
|
276
|
+
# {performer_id => <# performer >, ...}
|
277
|
+
def objectify_performers(performers)
|
278
|
+
performer_hash = {}
|
279
|
+
performers.each do |performer|
|
280
|
+
p = objectify_performer(performer)
|
281
|
+
performer_hash[p.id] = p
|
282
|
+
end if performers && !performers.empty?
|
283
|
+
performer_hash
|
284
|
+
end
|
285
|
+
|
286
|
+
# returns an array of events
|
287
|
+
def objectify_events(events, venues_hash)
|
288
|
+
(events || []).collect do |e|
|
289
|
+
objectify_event(e, venues_hash[e['vid'] || e['venue_id']])
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# Turns the event json into an event object
|
294
|
+
def objectify_event(event_hash, venue) ; Event.new(event_hash.merge(:venue => venue)) ; end
|
295
|
+
|
296
|
+
# Turns the venue json into a venue object
|
297
|
+
def objectify_venue(venue) ; Venue.new(venue) ; end
|
298
|
+
|
299
|
+
# Turns the performer json into a performer object
|
300
|
+
def objectify_performer(performer) ; Performer.new(performer) ; end
|
301
|
+
end
|
302
|
+
end
|
data/lib/zvent/venue.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Zvent
|
2
|
+
# An object that represents a single venue from zvents
|
3
|
+
class Venue < Base
|
4
|
+
attr_accessor :address, :city, :state, :country, :name, :latitude,
|
5
|
+
:longitude, :zip, :private, :id, :timezone, :zurl,
|
6
|
+
:types, :images, :phone, :url, :description, :parent_id
|
7
|
+
|
8
|
+
def initialize(venue_hash)
|
9
|
+
venue_hash.each_pair do |key, value|
|
10
|
+
begin
|
11
|
+
self.send("#{key}=", value)
|
12
|
+
rescue NoMethodError => e
|
13
|
+
#do nothing
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Zvents Partner API
|
18
|
+
self.url ||= venue_hash['link']
|
19
|
+
self.description ||= venue_hash['summary']
|
20
|
+
# TODO: external URLs
|
21
|
+
end
|
22
|
+
|
23
|
+
# Does the venue have any images
|
24
|
+
def images? ; !(@images.nil? || @images.empty?) ; end
|
25
|
+
|
26
|
+
def timezone? ; !(@timezone.nil? || @timezone.empty?) ; end
|
27
|
+
|
28
|
+
# Returns the tz timezone object
|
29
|
+
def tz_timezone ; timezone? ? TZInfo::Timezone.get(@timezone) : nil ; end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eostrom-zvent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Austin Fonacier, Erik Ostrom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: tzinfo
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.9
|
34
|
+
version:
|
35
|
+
description: " Interface for the zvents API without all the mess.\n"
|
36
|
+
email: afonacier@yellowpages.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- lib/zvent.rb
|
45
|
+
- lib/zvent/event.rb
|
46
|
+
- lib/zvent/venue.rb
|
47
|
+
- lib/zvent/performer.rb
|
48
|
+
- lib/zvent/base.rb
|
49
|
+
- lib/zvent/category.rb
|
50
|
+
- lib/zvent/session.rb
|
51
|
+
- lib/core/ext.rb
|
52
|
+
- README
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/austinrfnd/zvent-gem/
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: zvent
|
77
|
+
rubygems_version: 1.3.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Interface for the zvents API without all the mess.
|
81
|
+
test_files: []
|
82
|
+
|