upcoming-api 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/Rakefile +36 -0
- data/lib/upcoming.rb +8 -0
- data/lib/upcoming/auth.rb +47 -0
- data/lib/upcoming/category.rb +34 -0
- data/lib/upcoming/country.rb +53 -0
- data/lib/upcoming/event.rb +103 -0
- data/lib/upcoming/metro.rb +67 -0
- data/lib/upcoming/request.rb +33 -0
- data/lib/upcoming/state.rb +57 -0
- data/lib/upcoming/venue.rb +71 -0
- data/test/test_auth.rb +10 -0
- data/test/test_category.rb +16 -0
- data/test/test_country.rb +26 -0
- data/test/test_event.rb +9 -0
- data/test/test_metro.rb +20 -0
- data/test/test_request.rb +28 -0
- data/test/test_state.rb +27 -0
- metadata +63 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
desc 'run all tests'
|
4
|
+
task :test do
|
5
|
+
require 'rake/runtest'
|
6
|
+
Rake.run_tests 'test/test*.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'clean up all non source controlled files and directories'
|
10
|
+
task :clean do
|
11
|
+
FileUtils.rm_r('pkg', :force => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
Gem::manage_gems
|
16
|
+
require 'rake/gempackagetask'
|
17
|
+
|
18
|
+
spec = Gem::Specification.new do |s|
|
19
|
+
s.name = "upcoming-api"
|
20
|
+
s.version = "0.1"
|
21
|
+
s.author = "Larry Myers"
|
22
|
+
s.email = "larry@larrymyers.com"
|
23
|
+
s.homepage = "http://rubyforge.org/projects/upcoming-api/"
|
24
|
+
s.platform = Gem::Platform::RUBY
|
25
|
+
s.summary = "A ruby library for using the Upcoming.org REST API."
|
26
|
+
s.files = FileList["{tests,lib}/**/*","Rakefile","README"].to_a
|
27
|
+
s.require_path = "lib"
|
28
|
+
s.autorequire = "event"
|
29
|
+
s.test_files = FileList["test/test*.rb"].to_a
|
30
|
+
s.has_rdoc = true
|
31
|
+
s.extra_rdoc_files = ["README"]
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
35
|
+
pkg.need_tar = true
|
36
|
+
end
|
data/lib/upcoming.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
include REXML
|
3
|
+
|
4
|
+
module Upcoming
|
5
|
+
class Auth
|
6
|
+
API_KEY = 'change-me'
|
7
|
+
FROB = 'change-me'
|
8
|
+
|
9
|
+
attr_reader :token, :user_id, :user_name, :name
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@token = nil
|
13
|
+
@user_id = nil
|
14
|
+
@user_name = nil
|
15
|
+
@name = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_token
|
19
|
+
req = Upcoming::Request.new
|
20
|
+
resp = req.send({:method => 'auth.getToken', :frob => Upcoming::Auth::FROB})
|
21
|
+
|
22
|
+
doc = Document.new(resp.body)
|
23
|
+
el = XPath.first(doc, '//token')
|
24
|
+
|
25
|
+
@token = el.attribute('token').value
|
26
|
+
@user_id = el.attribute('user_id').value
|
27
|
+
@user_name = el.attribute('user_username').value
|
28
|
+
@name = el.attribute('user_name').value
|
29
|
+
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_token?
|
34
|
+
req = Upcoming::Request.new
|
35
|
+
resp = req.send({:method => 'auth.checkToken', :token => @token})
|
36
|
+
|
37
|
+
doc = Document.new(resp.body)
|
38
|
+
el = XPath.first(doc, '//token')
|
39
|
+
|
40
|
+
if el.nil?
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class Category
|
7
|
+
attr_reader :id, :name, :description
|
8
|
+
|
9
|
+
def initialize(id, name, description)
|
10
|
+
@id = id
|
11
|
+
@name = name
|
12
|
+
@description = description
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.info(category_id)
|
16
|
+
# TODO synthetic method, we'll have to call list and search it for a single id
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.list
|
20
|
+
categories = []
|
21
|
+
|
22
|
+
req = Upcoming::Request.new
|
23
|
+
resp = req.send({:method => 'category.getList'})
|
24
|
+
|
25
|
+
doc = Document.new(resp.body)
|
26
|
+
XPath.each(doc, '//category') do |el|
|
27
|
+
categories << Category.new(el.attribute('id').value,
|
28
|
+
el.attribute('name').value, el.attribute('description').value)
|
29
|
+
end
|
30
|
+
|
31
|
+
categories
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class Country
|
7
|
+
attr_reader :id, :name, :code
|
8
|
+
|
9
|
+
def initialize(id, name, code)
|
10
|
+
@id = id
|
11
|
+
@name = name
|
12
|
+
@code = code
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_info(country_id)
|
16
|
+
req = Upcoming::Request.new
|
17
|
+
resp = req.send({:method => 'country.getInfo', :country_id => country_id.to_s})
|
18
|
+
|
19
|
+
doc = Document.new(resp.body)
|
20
|
+
el = XPath.first(doc, '//country')
|
21
|
+
|
22
|
+
Country.new(el.attribute('id').value, el.attribute('name').value, el.attribute('code').value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_infos(country_id_list)
|
26
|
+
req = Upcoming::Request.new
|
27
|
+
resp = req.send({:method => 'country.getInfo', :country_id => country_id_list.join(',')})
|
28
|
+
|
29
|
+
countries = []
|
30
|
+
|
31
|
+
doc = Document.new(resp.body)
|
32
|
+
XPath.each(doc, '//country') do |c|
|
33
|
+
countries << Country.new(c.attribute('id').value, c.attribute('name').value, c.attribute('code').value)
|
34
|
+
end
|
35
|
+
|
36
|
+
countries
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_all_infos
|
40
|
+
req = Upcoming::Request.new
|
41
|
+
resp = req.send({:method => 'metro.getCountryList'})
|
42
|
+
|
43
|
+
countries = []
|
44
|
+
|
45
|
+
doc = Document.new(resp.body)
|
46
|
+
XPath.each(doc, '//country') do |c|
|
47
|
+
countries << Country.new(c.attribute('id').value, c.attribute('name').value, c.attribute('code').value)
|
48
|
+
end
|
49
|
+
|
50
|
+
countries
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
require 'upcoming/venue'
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class Event
|
7
|
+
|
8
|
+
attr_reader :id, :name, :description, :start_date, :end_date,
|
9
|
+
:start_time, :end_time, :date_posted, :personal, :self_promotion,
|
10
|
+
:lat, :lng, :gc_precision, :gc_ambiguous
|
11
|
+
|
12
|
+
def initialize(attrs_hash)
|
13
|
+
@id = attrs_hash[:id]
|
14
|
+
@name = attrs_hash[:name]
|
15
|
+
@description = attrs_hash[:description]
|
16
|
+
@start_date = attrs_hash[:start_date]
|
17
|
+
@end_date = attrs_hash[:end_date]
|
18
|
+
@start_time = attrs_hash[:start_time]
|
19
|
+
@end_time = attrs_hash[:end_time]
|
20
|
+
@date_posted = attrs_hash[:date_posted]
|
21
|
+
@personal = attrs_hash[:personal]
|
22
|
+
@self_promotion = attrs_hash[:self_promotion]
|
23
|
+
@lat = attrs_hash[:lat]
|
24
|
+
@lng = attrs_hash[:lng]
|
25
|
+
@gc_precision = attrs_hash[:gc_precision]
|
26
|
+
@gc_ambiguous = attrs_hash[:gc_ambiguous]
|
27
|
+
@user_id = attrs_hash[:user_id]
|
28
|
+
@category_id = attrs_hash[:category_id]
|
29
|
+
@venue_id = attrs_hash[:venue_id]
|
30
|
+
@metro_id = attrs_hash[:metro_id]
|
31
|
+
@state_id = attrs_hash[:state_id]
|
32
|
+
@country_id = attrs_hash[:country_id]
|
33
|
+
end
|
34
|
+
|
35
|
+
def user
|
36
|
+
# TODO get user info about event
|
37
|
+
end
|
38
|
+
|
39
|
+
def category
|
40
|
+
# TODO populate me intelligently
|
41
|
+
end
|
42
|
+
|
43
|
+
def venue
|
44
|
+
Upcoming::Venue.info(@venue_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def metro
|
48
|
+
# TODO get metro info for event
|
49
|
+
end
|
50
|
+
|
51
|
+
def state
|
52
|
+
# TODO get state info for event
|
53
|
+
end
|
54
|
+
|
55
|
+
def country
|
56
|
+
# TODO get country info for event
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.search(params)
|
60
|
+
params[:method] = 'event.search' if params[:method].nil?
|
61
|
+
|
62
|
+
req = Upcoming::Request.new
|
63
|
+
resp = req.send(params)
|
64
|
+
|
65
|
+
events = []
|
66
|
+
doc = Document.new(resp.body)
|
67
|
+
|
68
|
+
XPath.each(doc, '//event') { |el| events << Event.create_from_node(el) }
|
69
|
+
|
70
|
+
events
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.valid_params?(params)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.create_from_node(node)
|
77
|
+
attrs = {}
|
78
|
+
|
79
|
+
attrs[:id] = node.attribute('id').value
|
80
|
+
attrs[:name] = node.attribute('name').value
|
81
|
+
attrs[:description] = node.attribute('description').value
|
82
|
+
attrs[:start_date] = node.attribute('start_date').value
|
83
|
+
attrs[:end_date] = node.attribute('end_date').value
|
84
|
+
attrs[:start_time] = node.attribute('start_time').value
|
85
|
+
attrs[:end_time] = node.attribute('end_time').value
|
86
|
+
attrs[:date_posted] = node.attribute('date_posted').value
|
87
|
+
attrs[:personal] = node.attribute('personal').value
|
88
|
+
attrs[:self_promotion] = node.attribute('selfpromotion').value
|
89
|
+
attrs[:lat] = node.attribute('latitude').value
|
90
|
+
attrs[:lng] = node.attribute('longitude').value
|
91
|
+
attrs[:gc_precision] = node.attribute('geocoding_precision').value
|
92
|
+
attrs[:gc_ambiguous] = node.attribute('geocoding_ambiguous').value
|
93
|
+
attrs[:user_id] = node.attribute('user_id').value
|
94
|
+
attrs[:category_id] = node.attribute('category_id').value
|
95
|
+
attrs[:venue_id] = node.attribute('venue_id').value
|
96
|
+
attrs[:metro_id] = node.attribute('metro_id').value
|
97
|
+
attrs[:state_id] = node.attribute('venue_state_id').value
|
98
|
+
attrs[:country_id] = node.attribute('venue_country_id').value
|
99
|
+
|
100
|
+
Event.new(attrs)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
require 'upcoming/state'
|
4
|
+
require 'upcoming/country'
|
5
|
+
include REXML
|
6
|
+
|
7
|
+
module Upcoming
|
8
|
+
class Metro
|
9
|
+
attr_reader :id, :name, :code, :url, :state, :country
|
10
|
+
|
11
|
+
def initialize(id, name, code, url, state, country)
|
12
|
+
@id = id
|
13
|
+
@name = name
|
14
|
+
@code = code
|
15
|
+
@url = url
|
16
|
+
@state = state
|
17
|
+
@country = country
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.search(text, state_id=nil, country_id=nil)
|
21
|
+
metros = []
|
22
|
+
|
23
|
+
req = Upcoming::Request.new
|
24
|
+
resp = req.send({:method => 'metro.search', :search_text => text,
|
25
|
+
:state_id => state_id, :country_id => country_id})
|
26
|
+
|
27
|
+
doc = Document.new(resp.body)
|
28
|
+
|
29
|
+
XPath.each(doc, '//metro') do |m|
|
30
|
+
state = State.new(m.attribute('state_id').value, m.attribute('state_name').value,
|
31
|
+
m.attribute('state_code').value, m.attribute('country_id').value)
|
32
|
+
|
33
|
+
country = Country.new(m.attribute('country_id').value, m.attribute('country_name').value,
|
34
|
+
m.attribute('country_code').value)
|
35
|
+
|
36
|
+
metros << Metro.new(m.attribute('id').value, m.attribute('name').value,
|
37
|
+
m.attribute('code').value, m.attribute('url').value, state, country)
|
38
|
+
end
|
39
|
+
|
40
|
+
metros
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.get_info(metro_id)
|
44
|
+
# TODO implement me
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.get_infos(metro_id_list)
|
48
|
+
# TODO implement me
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.get_by_lat_lon(lat,lon)
|
52
|
+
# TODO implement me
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.list_by_state(state_id)
|
56
|
+
# TODO implement me
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.states(country_id)
|
60
|
+
Upcoming::State.get_all_infos(country_id)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.countries
|
64
|
+
Upcoming::Country.get_all_infos
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'upcoming/auth'
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class Request
|
7
|
+
URL = 'http://upcoming.yahooapis.com/services/rest/?'
|
8
|
+
|
9
|
+
def send(params)
|
10
|
+
url = get_url(params)
|
11
|
+
|
12
|
+
resp = nil
|
13
|
+
|
14
|
+
begin
|
15
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
16
|
+
rescue
|
17
|
+
puts 'Uh oh.'
|
18
|
+
end
|
19
|
+
|
20
|
+
resp
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_url(params)
|
24
|
+
url = URL + 'api_key=' + Auth::API_KEY
|
25
|
+
|
26
|
+
params.each do |k,v|
|
27
|
+
url << "&#{k.to_s}=#{URI.encode(v.to_s)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
url
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class State
|
7
|
+
attr_reader :id, :name, :code, :country_id
|
8
|
+
|
9
|
+
def initialize(id, name, code, country_id)
|
10
|
+
@id = id
|
11
|
+
@name = name
|
12
|
+
@code = code
|
13
|
+
@country_id = country_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_info(state_id)
|
17
|
+
req = Upcoming::Request.new
|
18
|
+
resp = req.send({:method => 'state.getInfo', :state_id => state_id.to_s})
|
19
|
+
|
20
|
+
doc = Document.new(resp.body)
|
21
|
+
el = XPath.first(doc, '//state')
|
22
|
+
|
23
|
+
State.new(el.attribute('id').value, el.attribute('name').value,
|
24
|
+
el.attribute('code').value, el.attribute('country_id').value)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_infos(state_id_list)
|
28
|
+
req = Upcoming::Request.new
|
29
|
+
resp = req.send({:method => 'state.getInfo', :state_id => state_id_list.join(',')})
|
30
|
+
|
31
|
+
states = []
|
32
|
+
|
33
|
+
doc = Document.new(resp.body)
|
34
|
+
XPath.each(doc, '//state') do |s|
|
35
|
+
states << State.new(s.attribute('id').value, s.attribute('name').
|
36
|
+
value, s.attribute('code').value, s.attribute('country_id').value)
|
37
|
+
end
|
38
|
+
|
39
|
+
states
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_all_infos(country_id)
|
43
|
+
states = []
|
44
|
+
|
45
|
+
req = Upcoming::Request.new
|
46
|
+
resp = req.send({:method => 'metro.getStateList', :country_id => country_id.to_s})
|
47
|
+
|
48
|
+
doc = Document.new(resp.body)
|
49
|
+
XPath.each(doc, '//state') do |s|
|
50
|
+
states << State.new(s.attribute('id').value, s.attribute('name').
|
51
|
+
value, s.attribute('code').value, country_id.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
states
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'upcoming/request'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
module Upcoming
|
6
|
+
class Venue
|
7
|
+
attr_reader :id, :name, :city, :url, :user_id, :lat, :lng, :gc_precision
|
8
|
+
|
9
|
+
def initialize(id, name, city, url, user_id, visibility, lat, lng, gc_precision)
|
10
|
+
@id = id
|
11
|
+
@name = name
|
12
|
+
@city = city
|
13
|
+
@url = url
|
14
|
+
@user_id = user_id
|
15
|
+
@visibility = visibility
|
16
|
+
@lat = lat
|
17
|
+
@lng = lng
|
18
|
+
@gc_precision = gc_precision
|
19
|
+
end
|
20
|
+
|
21
|
+
def private?
|
22
|
+
return false if @visibility.nil? || @visibility == 0
|
23
|
+
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.search(params)
|
28
|
+
# TODO implement venue search
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.info(venue_id, token=nil)
|
32
|
+
params = {:method => 'venue.getInfo', :venue_id => venue_id}
|
33
|
+
params[:token] = token unless token.nil?
|
34
|
+
|
35
|
+
req = Upcoming::Request.new
|
36
|
+
resp = req.send(params)
|
37
|
+
|
38
|
+
doc = Document.new(resp.body)
|
39
|
+
el = XPath.first(doc, '//venue')
|
40
|
+
|
41
|
+
Venue.new(
|
42
|
+
el.attribute('id').value,
|
43
|
+
el.attribute('name').value,
|
44
|
+
el.attribute('city').value,
|
45
|
+
el.attribute('url').value,
|
46
|
+
el.attribute('user_id').value,
|
47
|
+
el.attribute('private').value,
|
48
|
+
el.attribute('latitude').value,
|
49
|
+
el.attribute('longitude').value,
|
50
|
+
el.attribute('geocoding_precision').value
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.list(metro_id, token=nil)
|
55
|
+
params = {:method => 'venue.getList', :metro_id => metro_id}
|
56
|
+
params[:token] = token unless token.nil?
|
57
|
+
|
58
|
+
req = Upcoming::Request.new
|
59
|
+
resp = req.send(params)
|
60
|
+
|
61
|
+
venues = []
|
62
|
+
|
63
|
+
doc = Document.new(resp.body)
|
64
|
+
XPath.each(doc, '//venue') do |v|
|
65
|
+
# TODO parse my elements, yo!
|
66
|
+
end
|
67
|
+
|
68
|
+
venues
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/test/test_auth.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'upcoming/category'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestCategory < Test::Unit::TestCase
|
7
|
+
def test_get_category_list
|
8
|
+
cats = Upcoming::Category.list
|
9
|
+
|
10
|
+
assert_not_nil(cats)
|
11
|
+
assert_not_equal(0, cats.size)
|
12
|
+
assert_match(/^\d+$/, cats[0].id)
|
13
|
+
assert_instance_of(String, cats[0].name)
|
14
|
+
assert_instance_of(String, cats[0].description)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'upcoming/country'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestCountry < Test::Unit::TestCase
|
7
|
+
def test_get_info
|
8
|
+
c = Upcoming::Country.get_info(1)
|
9
|
+
|
10
|
+
assert_equal('1', c.id)
|
11
|
+
assert_equal('United States', c.name)
|
12
|
+
assert_equal('us', c.code)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_get_infos
|
16
|
+
countries = Upcoming::Country.get_infos([1,2,3])
|
17
|
+
|
18
|
+
assert_equal(3, countries.size)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_get_all_infos
|
22
|
+
countries = Upcoming::Country.get_all_infos
|
23
|
+
|
24
|
+
assert_not_equal(0, countries.size)
|
25
|
+
end
|
26
|
+
end
|
data/test/test_event.rb
ADDED
data/test/test_metro.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'upcoming/metro'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestMetro < Test::Unit::TestCase
|
7
|
+
def test_get_states
|
8
|
+
states = Upcoming::Metro.states(1)
|
9
|
+
|
10
|
+
assert_not_nil(states)
|
11
|
+
assert_not_equal(0, states.size)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_countries
|
15
|
+
countries = Upcoming::Metro.countries
|
16
|
+
|
17
|
+
assert_not_nil(countries)
|
18
|
+
assert_not_equal(0, countries)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'upcoming/request'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestRequest < Test::Unit::TestCase
|
7
|
+
def test_get_url
|
8
|
+
expected_url = 'http://upcoming.yahooapis.com/services/rest/'
|
9
|
+
expected_url << '?api_key=6c43a45521&metro_id=1&method=metro.getInfo'
|
10
|
+
|
11
|
+
params = {:method => 'metro.getInfo', :metro_id => '1'}
|
12
|
+
|
13
|
+
req = Upcoming::Request.new
|
14
|
+
|
15
|
+
assert_equal(expected_url, req.get_url(params))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_send
|
19
|
+
params = {:method => 'metro.getInfo', :metro_id => '1'}
|
20
|
+
|
21
|
+
req = Upcoming::Request.new
|
22
|
+
|
23
|
+
resp = req.send(params)
|
24
|
+
|
25
|
+
assert_not_nil(resp.body)
|
26
|
+
assert_not_equal('', resp.body)
|
27
|
+
end
|
28
|
+
end
|
data/test/test_state.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'upcoming/state'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestState < Test::Unit::TestCase
|
7
|
+
def test_get_info
|
8
|
+
s = Upcoming::State.get_info(1)
|
9
|
+
|
10
|
+
assert_equal('1', s.id)
|
11
|
+
assert_equal('Alabama', s.name)
|
12
|
+
assert_equal('al', s.code)
|
13
|
+
assert_equal('1', s.country_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_infos
|
17
|
+
states = Upcoming::State.get_infos([1,2,3])
|
18
|
+
|
19
|
+
assert_equal(3, states.size)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_get_all_infos
|
23
|
+
states = Upcoming::State.get_all_infos(1)
|
24
|
+
|
25
|
+
assert_not_equal(0, states.size)
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: upcoming-api
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2007-12-24 00:00:00 -05:00
|
8
|
+
summary: A ruby library for using the Upcoming.org REST API.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: larry@larrymyers.com
|
12
|
+
homepage: http://rubyforge.org/projects/upcoming-api/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: event
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Larry Myers
|
31
|
+
files:
|
32
|
+
- lib/upcoming
|
33
|
+
- lib/upcoming/auth.rb
|
34
|
+
- lib/upcoming/category.rb
|
35
|
+
- lib/upcoming/country.rb
|
36
|
+
- lib/upcoming/event.rb
|
37
|
+
- lib/upcoming/metro.rb
|
38
|
+
- lib/upcoming/request.rb
|
39
|
+
- lib/upcoming/state.rb
|
40
|
+
- lib/upcoming/venue.rb
|
41
|
+
- lib/upcoming.rb
|
42
|
+
- Rakefile
|
43
|
+
- README
|
44
|
+
test_files:
|
45
|
+
- test/test_auth.rb
|
46
|
+
- test/test_category.rb
|
47
|
+
- test/test_country.rb
|
48
|
+
- test/test_event.rb
|
49
|
+
- test/test_metro.rb
|
50
|
+
- test/test_request.rb
|
51
|
+
- test/test_state.rb
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- README
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
dependencies: []
|
63
|
+
|