Class: Zvent::Session
Overview
A zvent session used to search and everything
Instance Method Summary collapse
-
#find_event(event_id, zvent_options = {}, options = {}) ⇒ Object
Use this method to return a single event from zvents.
-
#find_events(location, zvent_options = {}, options = {}) ⇒ Object
Use this method to find events from zvents.
-
#initialize(api_key) ⇒ Session
constructor
Initializes the session object.
Methods inherited from Base
Constructor Details
#initialize(api_key) ⇒ Session
Initializes the session object. It requires an API key
5 6 7 8 |
# File 'lib/zvent/session.rb', line 5 def initialize(api_key) raise Zvent::NoApiKeyError.new if !api_key || api_key.strip.empty? @api_key = api_key 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
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/zvent/session.rb', line 75 def find_event(event_id, ={}, = {}) # event_id is required raise Zvent::NoIdError if event_id.strip.empty? #grab the json from zvents json_ret = get_resources(BASE_URL+"/event?#{.merge(:id => event_id).to_query}") #return the json or objectified json [: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
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zvent/session.rb', line 45 def find_events(location, = {}, = {}) #location is required raise Zvent::NoLocationError.new if !location || location.strip.empty? #grab the json from zvents json_ret = get_resources(BASE_URL+"/search?#{.merge(:where => location).to_query}") #return the json or objectified json [:as_json] ? json_ret : objectify_zvents_json(json_ret) end |