Class: Zvent::Session

Inherits:
Base show all
Defined in:
lib/zvent/session.rb

Overview

A zvent session used to search and everything

Constant Summary collapse

DEFAULT_BASE_URL =
"http://www.zvents.com/rest"
ZVENTS_DEFAULT_ARGUMENTS =

Default zvents arguments Image_size = none assures we just get the plain file name. Transformations to different sizes are done within the gem

{:image_size => 'none'}

Instance Method Summary collapse

Methods inherited from Base

#get_resources

Constructor Details

#initialize(api_key, options = {}) ⇒ Session

Initializes the session object. It requires an API key



11
12
13
14
15
# File 'lib/zvent/session.rb', line 11

def initialize(api_key, options = {})
  raise Zvent::NoApiKeyError.new if !api_key || api_key.strip.empty?
  @api_key = api_key
  @base_url = options[:base_url] || DEFAULT_BASE_URL
end

Instance Method Details

#find_event(event_id, zvent_options = {}, options = {}) ⇒ Object

Use this method to return a single event from zvents

Return returns an single event. If an event can not be found it will return nil <# event>

Arguments event_id

  • id - ID of the event

options

  • as_json - If set to true method will return the json from zvents without any transformation. (false by default).

Examples:

find_event('1234')
=> Finds an event with the id of 1234

find_event('1234', {:as_json => true})
=> Finds an event with the id of 1234 and returns the json as it comes in from zvents

Raises:



82
83
84
85
86
87
88
89
90
91
# File 'lib/zvent/session.rb', line 82

def find_event(event_id, zvent_options={}, options = {})
  # event_id is required
  raise Zvent::NoIdError if event_id.strip.empty?

  #grab the json from zvents
  json_ret = get_resources(@base_url+"/event?#{zvent_options.merge(:id => event_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_zvents_json(json_ret)[:events].first
end

#find_events(location, zvent_options = {}, options = {}) ⇒ Object

Use this method to find events from zvents.

Return returns a hash that contains an array of events and an event count => 10, :events => [<# event>, …]

Arguments

location

  • location - 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

zvent_options

  • what - The string against which events are matched. (e.g., parade). (default = nil, which searches for everything)

  • when - 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.

  • radius - 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.

  • limit - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(Default = 10. Max = 25)

  • offset - 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. (Default = 0)

  • trim - 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.

  • sort - Set to 1 to sort search results by start time. Set to 0 to sort search results by relevance. Defaults to 0.

  • cat - 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.

  • catex - Exclude items from a specific category from the search. You must provide a category identifier which can be determined using the categories API call.

options

  • as_json - If set to true method will return the json from zvents without any transformation. (false by default).

Examples:

find_events('93063')
=> Finds any 10 events near the 93063 zip code area.

find_events('611 N. Brand Blvd. Glendale, Ca', {:what => 'dancing', :limit => 25})
=> Finds 25 events near the address that consists of dancing

find_events('611 N. Brand Blvd. Glendale, Ca', {:what => 'dancing'}, {:as_json => true})
=> Should return the json straight from zvents


52
53
54
55
56
57
58
59
60
61
# File 'lib/zvent/session.rb', line 52

def find_events(location, zvent_options = {}, options = {})
  #location is required
  raise Zvent::NoLocationError.new if !location || location.strip.empty?

  #grab the json from zvents
  json_ret = get_resources(@base_url+"/search?#{zvent_options.merge(:where => location).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
end

#find_performers(what, zvent_options = {}, options = {}) ⇒ Object

Use this method to find performers from zvents.

Return returns a hash that contains an array of performers and a performer count => 10, :performers => [<# performer>, …]

Arguments

what

  • what - The string against which items are matched in the search. (e.g., parade).

zvent_options

  • limit - The maximum number of matching performers to return.

Examples:

find_performers('Cirque du Soleil')
=> Finds any 10 performers matching Cirque du Soleil

find_performers('Cirque du Soleil', :limit => 1)
=> Finds any 1 performer matching Cirque du Soleil

find_performers('Cirque du Soleil', {:as_json => true})
=> Finds performers and returns the result as JSON


200
201
202
203
204
205
206
# File 'lib/zvent/session.rb', line 200

def find_performers(what, zvent_options = {}, options = {})
  #grab the json from zvents
  json_ret = get_resources(@base_url+"/search_for_performers?#{zvent_options.merge(:what => what).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_performers_json(json_ret)
end

#find_venues(location, zvent_options = {}, options = {}) ⇒ Object

Use this method to find venues from zvents.

Return returns a hash that contains an array of venues and a venue count => 10, :venues => [<# venue>, …]

Arguments

location

  • location - 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

zvent_options

  • what - The string against which venues are matched. (e.g., parade). (default = nil, which searches for everything)

  • radius - 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.

  • limit - The maximum number of matching venues to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(Default = 10. Max = 25)

  • offset - 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. (Default = 0)

  • vt - Restrict your search to items that belong to a specific venue type. You must provide a venue type id.

options

  • as_json - If set to true method will return the json from zvents without any transformation. (false by default).

Examples:

find_venues('93063')
=> Finds any 10 venues near the 93063 zip code area.

find_venues('611 N. Brand Blvd. Glendale, Ca', {:what => 'museum', :limit => 25})
=> Finds 25 venues near the address that match 'museum'

find_venues('611 N. Brand Blvd. Glendale, Ca', {:what => 'museum'}, {:as_json => true})
=> Should return the json straight from zvents


124
125
126
127
128
129
130
131
132
133
# File 'lib/zvent/session.rb', line 124

def find_venues(location, zvent_options = {}, options = {})
  #location is required
  raise Zvent::NoLocationError.new if !location || location.strip.empty?

  #grab the json from zvents
  json_ret = get_resources(@base_url+"/search_for_venues?#{zvent_options.merge(:where => location).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_venues_json(json_ret)
end

#performer_events(performer_id, zvent_options = {}, options = {}) ⇒ Object

Use this method to find events for a given performer from zvents.

Return returns a hash that contains an array of events and an event count => 10, :events => [<# event>, …]

Arguments

performer_id

  • performer_id - ID of the performer, gleaned from an earlier Zvents call

zvent_options

  • limit - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(Default = 10. Max = 25)

  • when - 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.

options

  • as_json - If set to true method will return the json from zvents without any transformation. (false by default).

Examples:

performer_events(9955)
=> Finds any 10 events for performer ID 9955

performer_events(performer.id)
=> Finds any 10 events for the given Zvents::Performer

performer_events(performer.id, {:sd => '12/31/2009'}, {:as_json => true})
=> Finds events starting on New Year's Eve, and returns json


235
236
237
238
239
240
241
242
243
244
# File 'lib/zvent/session.rb', line 235

def performer_events(performer_id, zvent_options = {}, options = {})
  performer_id = performer_id.to_i
  raise Zvent::NoLocationError.new if performer_id == 0

  #grab the json from zvents
  json_ret = get_resources(@base_url+"/performer_events?#{zvent_options.merge(:id => performer_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
end

#venue_events(venue_id, zvent_options = {}, options = {}) ⇒ Object

Use this method to find events at a given venue from zvents.

Return returns a hash that contains an array of events and an event count => 10, :events => [<# event>, …]

Arguments

venue_id

  • venue_id - ID of the venue, gleaned from an earlier Zvents call

zvent_options

  • limit - The maximum number of matching events to return. The default is 10 and maximum is 10. Zvents partners can exceed the maximum.(Default = 10. Max = 25)

  • offset - 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. (Default = 0)

  • sd - Return only events that start on or after this date. (format: MM/DD/YYYY, defaults to today)

  • ed - 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)

  • st - Return only events that start at or after this time. (format: seconds since the epoch, e.g., 1142399089)

  • et - 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)

options

  • as_json - If set to true method will return the json from zvents without any transformation. (false by default).

Examples:

venue_events(9955)
=> Finds any 10 events for venue ID 9955

venue_events(venue.id)
=> Finds any 10 events for the given Zvents::Venue

venue_events(venue.id, {:sd => '12/31/2009'}, {:as_json => true})
=> Finds events starting on New Year's Eve, and returns json


166
167
168
169
170
171
172
173
174
175
# File 'lib/zvent/session.rb', line 166

def venue_events(venue_id, zvent_options = {}, options = {})
  venue_id = venue_id.to_i
  raise Zvent::NoLocationError.new if venue_id == 0

  #grab the json from zvents
  json_ret = get_resources(@base_url+"/venue_events?#{zvent_options.merge(:id => venue_id).merge(ZVENTS_DEFAULT_ARGUMENTS).to_query}")

  #return the json or objectified json
  options[:as_json] ? json_ret : objectify_zvents_json(json_ret)
end