Created
September 5, 2008 04:44
-
-
Save reagent/8925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'httparty' | |
module Upcoming | |
class Base | |
include HTTParty | |
format :xml | |
def self.api_key=(api_key) | |
default_params :api_key => api_key | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/base' | |
module Upcoming | |
class Event < Base | |
base_uri 'upcoming.yahooapis.com' | |
def initialize(params) | |
@params = params['rsp'].nil? ? params : params['rsp']['event'] | |
end | |
def self.find(id) | |
params = get('/services/rest/', :query => {:method => 'event.getInfo', :event_id => id}) | |
self.new(params) | |
end | |
def method_missing(method_name, *args) | |
@params[method_name.to_s] if @params.has_key?(method_name.to_s) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/base' | |
require File.dirname(__FILE__) + '/event' | |
module Upcoming | |
class EventCollection < Base | |
base_uri 'upcoming.yahooapis.com' | |
# Single response | |
# {"rsp"=>{"event"=>{"ticket_price"=>"", "venue_state_code"=>"dc", "watchlist_count"=>"1", "end_date"=>"", "start_date"=>"2008-09-12", "name"=>"another event in the future", "latitude"=>"38.8855", "selfpromotion"=>"1", "photo_url"=>"", "ticket_free"=>"0", "venue_state_id"=>"9", "venue_country_name"=>"United States", "geocoding_precision"=>"address", "url"=>"", "venue_id"=>"19384", "personal"=>"0", "venue_city"=>"Arlington", "venue_name"=>"Murky Coffee", "date_posted"=>"2008-09-04 22:10:59", "metro_id"=>"64;171", "id"=>"1076319", "venue_zip"=>"22201", "venue_country_code"=>"us", "category_id"=>"1", "description"=>"another event", "venue_address"=>"3211 Wilson Boulevard", "geocoding_ambiguous"=>"0", "longitude"=>"-77.0978", "user_id"=>"106191", "venue_country_id"=>"1", "venue_state_name"=>"District of Columbia", "ticket_url"=>"", "end_time"=>"-00001", "start_time"=>"20:00:00"}, "version"=>"1.0", "stat"=>"ok"}} | |
# Multiple responses | |
# {"rsp"=>{"event"=>[{"ticket_price"=>"", "venue_state_code"=>"dc", "watchlist_count"=>"1", "end_date"=>"", "start_date"=>"2008-09-06", "name"=>"hacky time", "latitude"=>"38.8855", "selfpromotion"=>"1", "photo_url"=>"", "ticket_free"=>"0", "venue_state_id"=>"9", "venue_country_name"=>"United States", "geocoding_precision"=>"address", "url"=>"", "venue_id"=>"19384", "personal"=>"0", "venue_city"=>"Arlington", "venue_name"=>"Murky Coffee", "date_posted"=>"2008-09-06 15:26:17", "metro_id"=>"64;171", "id"=>"1080064", "venue_zip"=>"22201", "venue_country_code"=>"us", "category_id"=>"1", "description"=>"just a test to pull hacky info", "venue_address"=>"3211 Wilson Boulevard", "geocoding_ambiguous"=>"0", "longitude"=>"-77.0978", "user_id"=>"106191", "venue_country_id"=>"1", "venue_state_name"=>"District of Columbia", "ticket_url"=>"", "end_time"=>"-00001", "start_time"=>"20:00:00"}, {"ticket_price"=>"", "venue_state_code"=>"dc", "watchlist_count"=>"1", "end_date"=>"", "start_date"=>"2008-09-12", "name"=>"another event in the future", "latitude"=>"38.8855", "selfpromotion"=>"1", "photo_url"=>"", "ticket_free"=>"0", "venue_state_id"=>"9", "venue_country_name"=>"United States", "geocoding_precision"=>"address", "url"=>"", "venue_id"=>"19384", "personal"=>"0", "venue_city"=>"Arlington", "venue_name"=>"Murky Coffee", "date_posted"=>"2008-09-04 22:10:59", "metro_id"=>"64;171", "id"=>"1076319", "venue_zip"=>"22201", "venue_country_code"=>"us", "category_id"=>"1", "description"=>"another event", "venue_address"=>"3211 Wilson Boulevard", "geocoding_ambiguous"=>"0", "longitude"=>"-77.0978", "user_id"=>"106191", "venue_country_id"=>"1", "venue_state_name"=>"District of Columbia", "ticket_url"=>"", "end_time"=>"-00001", "start_time"=>"20:00:00"}], "version"=>"1.0", "stat"=>"ok"}} | |
def self.by_tag(tag) | |
params = get('/services/rest/', :query => {:method => 'event.search', :tags => tag}) | |
event_list = Array(params['rsp']['event']) | |
event_list.map {|element| Event.new(element) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment