Active 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.bnsignore +18 -0
- data/Active-0.0.0.gem +0 -0
- data/Active.gemspec +36 -0
- data/History.txt +4 -0
- data/README.txt +48 -0
- data/Rakefile +17 -0
- data/bin/Active +7 -0
- data/lib/Active.rb +65 -0
- data/lib/services/activity.rb +34 -0
- data/lib/services/search.rb +127 -0
- data/spec/.DS_Store +0 -0
- data/spec/Active_spec.rb +6 -0
- data/spec/activity_spec.rb +97 -0
- data/spec/search_spec.rb +112 -0
- data/spec/spec_helper.rb +14 -0
- data/test/test_Active.rb +0 -0
- data/version.txt +1 -0
- metadata +103 -0
data/.DS_Store
ADDED
|
Binary file
|
data/.bnsignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
|
2
|
+
# Lines that start with '#' are comments.
|
|
3
|
+
#
|
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
|
5
|
+
# file in your Rakefile:
|
|
6
|
+
#
|
|
7
|
+
# Bones {
|
|
8
|
+
# ignore_file '.gitignore'
|
|
9
|
+
# }
|
|
10
|
+
#
|
|
11
|
+
# For a project with a C extension, the following would be a good set of
|
|
12
|
+
# exclude patterns (uncomment them if you want to use them):
|
|
13
|
+
# *.[oa]
|
|
14
|
+
# *~
|
|
15
|
+
announcement.txt
|
|
16
|
+
coverage
|
|
17
|
+
doc
|
|
18
|
+
pkg
|
data/Active-0.0.0.gem
ADDED
|
Binary file
|
data/Active.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{Active}
|
|
5
|
+
s.version = "0.0.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Jonathan Spooner, Brian Levine"]
|
|
9
|
+
s.date = %q{2010-08-31}
|
|
10
|
+
s.default_executable = %q{Active}
|
|
11
|
+
s.description = %q{Search api for Active Network}
|
|
12
|
+
s.email = %q{jspooner [at] gmail.com}
|
|
13
|
+
s.executables = ["Active"]
|
|
14
|
+
s.extra_rdoc_files = ["History.txt", "README.txt", "bin/Active", "version.txt"]
|
|
15
|
+
s.files = [".DS_Store", ".bnsignore", "Active.gemspec", "History.txt", "README.txt", "Rakefile", "bin/Active", "lib/Active.rb", "lib/services/activity.rb", "lib/services/search.rb", "spec/.DS_Store", "spec/Active_spec.rb", "spec/activity_spec.rb", "spec/search_spec.rb", "spec/spec_helper.rb", "test/test_Active.rb", "version.txt"]
|
|
16
|
+
s.homepage = %q{http://developer.active.com/docs/Activecom_Search_API_Reference}
|
|
17
|
+
s.rdoc_options = ["--main", "README.txt"]
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
s.rubyforge_project = %q{Active}
|
|
20
|
+
s.rubygems_version = %q{1.3.7}
|
|
21
|
+
s.summary = %q{Search api for Active Network}
|
|
22
|
+
s.test_files = ["test/test_Active.rb"]
|
|
23
|
+
|
|
24
|
+
if s.respond_to? :specification_version then
|
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
26
|
+
s.specification_version = 3
|
|
27
|
+
|
|
28
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
29
|
+
s.add_development_dependency(%q<bones>, [">= 3.4.7"])
|
|
30
|
+
else
|
|
31
|
+
s.add_dependency(%q<bones>, [">= 3.4.7"])
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
s.add_dependency(%q<bones>, [">= 3.4.7"])
|
|
35
|
+
end
|
|
36
|
+
end
|
data/History.txt
ADDED
data/README.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Active
|
|
2
|
+
by Jonathan Spooner and Brian Levine
|
|
3
|
+
http://developer.active.com/docs/Activecom_Search_API_Reference
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
Search api for Active Network
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
* Seach API
|
|
12
|
+
|
|
13
|
+
== SYNOPSIS:
|
|
14
|
+
|
|
15
|
+
Search.search( {:location => "San Diego, CA, US"} )
|
|
16
|
+
|
|
17
|
+
== REQUIREMENTS:
|
|
18
|
+
|
|
19
|
+
* none
|
|
20
|
+
|
|
21
|
+
== INSTALL:
|
|
22
|
+
|
|
23
|
+
* sudo gem install active
|
|
24
|
+
|
|
25
|
+
== LICENSE:
|
|
26
|
+
|
|
27
|
+
(The MIT License)
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2009 FIXME (different license?)
|
|
30
|
+
|
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
32
|
+
a copy of this software and associated documentation files (the
|
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
37
|
+
the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be
|
|
40
|
+
included in all copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
begin
|
|
3
|
+
require 'bones'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
abort '### Please install the "bones" gem ###'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
task :default => 'test:run'
|
|
9
|
+
task 'gem:release' => 'test:run'
|
|
10
|
+
|
|
11
|
+
Bones {
|
|
12
|
+
name 'Active'
|
|
13
|
+
authors 'Jonathan Spooner, Brian Levine'
|
|
14
|
+
email 'jspooner [at] gmail.com'
|
|
15
|
+
url 'http://developer.active.com/docs/Activecom_Search_API_Reference'
|
|
16
|
+
}
|
|
17
|
+
|
data/bin/Active
ADDED
data/lib/Active.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
module Active
|
|
3
|
+
|
|
4
|
+
# :stopdoc:
|
|
5
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
|
6
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
|
7
|
+
# :startdoc:
|
|
8
|
+
|
|
9
|
+
# Returns the version string for the library.
|
|
10
|
+
#
|
|
11
|
+
def self.version
|
|
12
|
+
@version ||= File.read(path('version.txt')).strip
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Returns the library path for the module. If any arguments are given,
|
|
16
|
+
# they will be joined to the end of the libray path using
|
|
17
|
+
# <tt>File.join</tt>.
|
|
18
|
+
#
|
|
19
|
+
def self.libpath( *args, &block )
|
|
20
|
+
rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
|
21
|
+
if block
|
|
22
|
+
begin
|
|
23
|
+
$LOAD_PATH.unshift LIBPATH
|
|
24
|
+
rv = block.call
|
|
25
|
+
ensure
|
|
26
|
+
$LOAD_PATH.shift
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
return rv
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Returns the lpath for the module. If any arguments are given,
|
|
33
|
+
# they will be joined to the end of the path using
|
|
34
|
+
# <tt>File.join</tt>.
|
|
35
|
+
#
|
|
36
|
+
def self.path( *args, &block )
|
|
37
|
+
rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
|
38
|
+
if block
|
|
39
|
+
begin
|
|
40
|
+
$LOAD_PATH.unshift PATH
|
|
41
|
+
rv = block.call
|
|
42
|
+
ensure
|
|
43
|
+
$LOAD_PATH.shift
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
return rv
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Utility method used to require all files ending in .rb that lie in the
|
|
50
|
+
# directory below this file that has the same name as the filename passed
|
|
51
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
|
52
|
+
# the _filename_ does not have to be equivalent to the directory.
|
|
53
|
+
#
|
|
54
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
|
55
|
+
dir ||= ::File.basename(fname, '.*')
|
|
56
|
+
search_me = ::File.expand_path(
|
|
57
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
|
58
|
+
|
|
59
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end # module Active
|
|
63
|
+
|
|
64
|
+
Active.require_all_libs_relative_to(__FILE__)
|
|
65
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Active
|
|
2
|
+
module Services
|
|
3
|
+
class Activity
|
|
4
|
+
attr_accessor :title, :address, :start_date, :start_time, :end_time, :end_date, :category, :desc
|
|
5
|
+
def initialize data
|
|
6
|
+
data = HashWithIndifferentAccess.new(data)
|
|
7
|
+
@title = data[:title]
|
|
8
|
+
|
|
9
|
+
unless data[:meta].nil?
|
|
10
|
+
@start_date = data[:meta][:startDate] ||= ""
|
|
11
|
+
@end_date = data[:meta][:endDate] ||= ""
|
|
12
|
+
@category = data[:meta][:channel] ||= ""
|
|
13
|
+
@desc = data[:meta][:description] ||= ""
|
|
14
|
+
@start_time = data[:meta][:startTime] ||= ""
|
|
15
|
+
@end_time = data[:meta][:endTime] ||= ""
|
|
16
|
+
@address = {
|
|
17
|
+
:name => data[:meta][:location],
|
|
18
|
+
# # :address => data[:meta][''], || "" ,
|
|
19
|
+
:city => data[:meta][:city],
|
|
20
|
+
:state => data[:meta][:state],
|
|
21
|
+
:zip => data[:meta][:zip],
|
|
22
|
+
:lat => data[:meta][:latitude],
|
|
23
|
+
:lng => data[:meta][:longitude],
|
|
24
|
+
:country => data[:meta][:country]
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
@onlineDonationAvailable = data[:meta][:onlineDonationAvailable]
|
|
28
|
+
@onlineRegistrationAvailable = data[:meta][:onlineRegistrationAvailable]
|
|
29
|
+
@onlineMembershipAvailable = data[:meta][:onlineMembershipAvailable]
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'cgi'
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'mysql'
|
|
6
|
+
require 'active_record'
|
|
7
|
+
|
|
8
|
+
module Active
|
|
9
|
+
module Services
|
|
10
|
+
|
|
11
|
+
class Sort
|
|
12
|
+
def self.DATE_ASC
|
|
13
|
+
"date_asc"
|
|
14
|
+
end
|
|
15
|
+
def self.DATE_DESC
|
|
16
|
+
"date_desc"
|
|
17
|
+
end
|
|
18
|
+
def self.RELEVANCE
|
|
19
|
+
"relevance"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Facet
|
|
24
|
+
def self.ACTIVITIES
|
|
25
|
+
"activities"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Search
|
|
32
|
+
# attr_accessor :location, :category, :channels, :daterange, :keywords, :radius, :limit, :sort, :page, :offset,
|
|
33
|
+
# :asset_type_id, :api_key, :num_results, :view, :facet, :sort
|
|
34
|
+
#
|
|
35
|
+
SEARCH_URL = "http://search.active.com"
|
|
36
|
+
DEFAULT_TIMEOUT = 5
|
|
37
|
+
# @page = 1
|
|
38
|
+
# @num_results = 10
|
|
39
|
+
# @api_key = ""
|
|
40
|
+
# @location = "San Diego, CA, US"
|
|
41
|
+
# @view = "json"
|
|
42
|
+
# @facet = Facet.ACTIVITIES
|
|
43
|
+
# @sort = Sort.DATE_ASC
|
|
44
|
+
|
|
45
|
+
# http://developer.active.com/docs/Activecom_Search_API_Reference
|
|
46
|
+
#
|
|
47
|
+
def self.search(data=nil)
|
|
48
|
+
searchurl = URI.parse(construct_url(data))
|
|
49
|
+
req = Net::HTTP::Get.new(searchurl.path)
|
|
50
|
+
http = Net::HTTP.new(searchurl.host, searchurl.port)
|
|
51
|
+
http.read_timeout = DEFAULT_TIMEOUT
|
|
52
|
+
|
|
53
|
+
res = http.start { |http|
|
|
54
|
+
http.get("#{searchurl.path}?#{searchurl.query}")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if res.code == '200'
|
|
58
|
+
parsed_json = JSON.parse(res.body)
|
|
59
|
+
parsed_json['_results'].collect { |a| Activity.new(a) }
|
|
60
|
+
else
|
|
61
|
+
raise RuntimeError, "Active Search responded with a #{res.code} for your query."
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.construct_url(arg_options={})
|
|
66
|
+
options = {
|
|
67
|
+
:api_key => "",
|
|
68
|
+
:view => "json",
|
|
69
|
+
:facet => Facet.ACTIVITIES,
|
|
70
|
+
:sort => Sort.DATE_ASC,
|
|
71
|
+
:radius => "10",
|
|
72
|
+
:meta => "",
|
|
73
|
+
:num_results => "10",
|
|
74
|
+
:page => "1",
|
|
75
|
+
:location => "",
|
|
76
|
+
:search => "",
|
|
77
|
+
:keywords => [],
|
|
78
|
+
:channels => nil,
|
|
79
|
+
:start_date => "today",
|
|
80
|
+
:end_date => "+"
|
|
81
|
+
}
|
|
82
|
+
options.merge!(arg_options)
|
|
83
|
+
|
|
84
|
+
options[:location] = CGI.escape(options[:location]) if options[:location]
|
|
85
|
+
|
|
86
|
+
if options[:keywords].class == String
|
|
87
|
+
options[:keywords] = options[:keywords].split(",")
|
|
88
|
+
options[:keywords].each { |k| k.strip! }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
channels_str = ""
|
|
92
|
+
|
|
93
|
+
if options[:channels] != nil
|
|
94
|
+
channels_a = options[:channels].collect { |channel|
|
|
95
|
+
"meta:channel=#{URI.escape(URI.escape(channel, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")),Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")).gsub(/\-/,"%252D")}"
|
|
96
|
+
}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
meta_data = ""
|
|
100
|
+
meta_data = channels_a.join("+OR+") if channels_a
|
|
101
|
+
|
|
102
|
+
meta_data += "+AND+" unless meta_data == ""
|
|
103
|
+
if options[:start_date].class == Date
|
|
104
|
+
options[:start_date] = URI.escape(options[:start_date].strftime("%m/%d/%Y")).gsub(/\//,"%2F")
|
|
105
|
+
end
|
|
106
|
+
if options[:end_date].class == Date
|
|
107
|
+
options[:end_date] = URI.escape(options[:end_date].strftime("%m/%d/%Y")).gsub(/\//,"%2F")
|
|
108
|
+
end
|
|
109
|
+
meta_data += "daterange:#{options[:start_date]}..#{options[:end_date]}"
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
# if @asset_type_id!=nil
|
|
113
|
+
# @meta = @meta + "+AND+" if @meta!=""
|
|
114
|
+
# @meta = @meta + "inmeta:assetTypeId=#{@asset_type_id}"
|
|
115
|
+
# end
|
|
116
|
+
#
|
|
117
|
+
url = "#{SEARCH_URL}/search?api_key=#{options[:api_key]}&num=#{options[:num_results]}&page=#{options[:page]}&l=#{options[:location]}&f=#{options[:facet]}&v=#{options[:view]}&r=#{options[:radius]}&s=#{options[:sort]}&k=#{options[:keywords].join("+")}&m=#{meta_data}"
|
|
118
|
+
puts url
|
|
119
|
+
url
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
data/spec/.DS_Store
ADDED
|
Binary file
|
data/spec/Active_spec.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Require the spec helper relative to this file
|
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
|
3
|
+
require File.join(File.dirname(__FILE__), %w[ .. lib services search])
|
|
4
|
+
|
|
5
|
+
# No need to type Britify:: before each call
|
|
6
|
+
include Active::Services
|
|
7
|
+
|
|
8
|
+
describe Activity do
|
|
9
|
+
before(:each) do
|
|
10
|
+
@valid_attributes = {
|
|
11
|
+
:title => "2011 Walt Disney World\xAE Marathon | Lake Buena Vista, Florida <b>...</b>",
|
|
12
|
+
:url => "http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011",
|
|
13
|
+
:language => "en",
|
|
14
|
+
:meta => {
|
|
15
|
+
:trackbackurl => "http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011",
|
|
16
|
+
:substitutionUrl => "1820830",
|
|
17
|
+
:assetId => ['3584C7D6-14FD-4FD1-BD07-C2A9B2925B6C','3584c7d6-14fd-4fd1-bd07-c2a9b2925b6c'],
|
|
18
|
+
:city => "Lake Buena Vista",
|
|
19
|
+
:latitude => "28.39494",
|
|
20
|
+
:category => "Activities",
|
|
21
|
+
:zip => "32830",
|
|
22
|
+
:eventId => "1820830",
|
|
23
|
+
:eventLongitude => "-81.56783",
|
|
24
|
+
:location => "Walt Disney World Resort",
|
|
25
|
+
:eventDate => "2011-01-09T05:40:00-08:00",
|
|
26
|
+
:country => 'United States',
|
|
27
|
+
:participationCriteria => 'Adult',
|
|
28
|
+
:locationName => "Walt Disney World Resort",
|
|
29
|
+
:sortDate => "2001-01-09",
|
|
30
|
+
:lastModifiedDate => "2010-08-17",
|
|
31
|
+
:image1 => 'http://www.active.com/images/events/hotrace.gif',
|
|
32
|
+
:lastModifiedDateTime => "2010-08-17 21:00:03.77",
|
|
33
|
+
:eventState => "Florida",
|
|
34
|
+
:contactPhone => "407-938-3398",
|
|
35
|
+
:startDate => "2011-01-09",
|
|
36
|
+
:onlineDonationAvailable => "true",
|
|
37
|
+
:channel => "Running",
|
|
38
|
+
:assetTypeId => "3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6",
|
|
39
|
+
:UpdateDateTime => "8/18/2010 10:16:26 AM",
|
|
40
|
+
:contactEmail => 'wdw.sports.marathon.endurance@disneysports.com',
|
|
41
|
+
:longitude => "-81.56783",
|
|
42
|
+
:description => "This is the description",
|
|
43
|
+
:startTime => "5:40:00",
|
|
44
|
+
:endTime => "5:40:00",
|
|
45
|
+
:eventZip => "32830",
|
|
46
|
+
:onlineRegistrationAvailable => "true",
|
|
47
|
+
:onlineMembershipAvailable => "false",
|
|
48
|
+
:endDate => "2011-01-09",
|
|
49
|
+
:keywords => "Event",
|
|
50
|
+
:eventLatitude => "28.39494",
|
|
51
|
+
:state => "Florida"
|
|
52
|
+
},
|
|
53
|
+
:escapedUrl => 'http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011',
|
|
54
|
+
:summary => "This is the summary."
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should be a valid activity" do
|
|
59
|
+
a = Activity.new(@valid_attributes)
|
|
60
|
+
a.title.should_not be_nil
|
|
61
|
+
a.start_date.should_not be_nil
|
|
62
|
+
a.end_date.should_not be_nil
|
|
63
|
+
a.category.should_not be_nil
|
|
64
|
+
a.desc.should_not be_nil
|
|
65
|
+
a.start_time.should_not be_nil
|
|
66
|
+
a.end_time.should_not be_nil
|
|
67
|
+
|
|
68
|
+
a.address.should_not be_nil
|
|
69
|
+
a.address[:city].should_not be_nil
|
|
70
|
+
a.address[:state].should_not be_nil
|
|
71
|
+
a.address[:country].should_not be_nil
|
|
72
|
+
a.address[:zip].should_not be_nil
|
|
73
|
+
a.address[:lat].should_not be_nil
|
|
74
|
+
a.address[:lng].should_not be_nil
|
|
75
|
+
a.address[:name].should_not be_nil
|
|
76
|
+
|
|
77
|
+
# a.onlineDonationAvailable.should_not be_nil
|
|
78
|
+
# a.onlineRegistrationAvailable.should_not be_nil
|
|
79
|
+
# a.onlineMembershipAvailable.should_not be_nil
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
# :tag:
|
|
87
|
+
# :- event:10
|
|
88
|
+
# :- Running:10
|
|
89
|
+
# :splitMediaType:
|
|
90
|
+
# :- Event
|
|
91
|
+
# :- Marathon
|
|
92
|
+
# :assetName:
|
|
93
|
+
# :- "2011 Walt Disney World\xAE Marathon"
|
|
94
|
+
# :- "2011 Walt Disney World\xAE Marathon"
|
|
95
|
+
# mediaType:
|
|
96
|
+
# - Event
|
|
97
|
+
# - Event\Marathon
|
data/spec/search_spec.rb
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'fake_web'
|
|
2
|
+
# Require the spec helper relative to this file
|
|
3
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
|
4
|
+
require File.join(File.dirname(__FILE__), %w[ .. lib services search])
|
|
5
|
+
require File.join(File.dirname(__FILE__), %w[ .. lib services activity])
|
|
6
|
+
|
|
7
|
+
# No need to type Britify:: before each call
|
|
8
|
+
include Active::Services
|
|
9
|
+
|
|
10
|
+
describe "Search URL Construction" do
|
|
11
|
+
|
|
12
|
+
it "should construct a valid url with location" do
|
|
13
|
+
url = Search.construct_url( {:location => "San Diego, CA, US"} )
|
|
14
|
+
uri = URI.parse(url)
|
|
15
|
+
uri.scheme.should eql("http")
|
|
16
|
+
uri.host.should eql("search.active.com")
|
|
17
|
+
uri.query.include?("l=#{CGI.escape("San Diego, CA, US")}").should be_true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should construct a valid url with CSV keywords" do
|
|
21
|
+
uri = URI.parse( Search.construct_url( {:keywords => "running, tri"} ) )
|
|
22
|
+
uri.query.include?("k=running+tri").should be_true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should construct a valid url with keywords array" do
|
|
26
|
+
uri = URI.parse( Search.construct_url( {:keywords => ["running","tri","cycling"]} ) )
|
|
27
|
+
uri.query.include?("k=running+tri+cycling").should be_true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should have defaults set" do
|
|
31
|
+
uri = URI.parse( Search.construct_url() )
|
|
32
|
+
uri.query.include?("f=#{Facet.ACTIVITIES}").should be_true
|
|
33
|
+
uri.query.include?("s=#{Sort.DATE_ASC}").should be_true
|
|
34
|
+
uri.query.include?("r=10").should be_true
|
|
35
|
+
uri.query.include?("v=json").should be_true
|
|
36
|
+
uri.query.include?("page=1").should be_true
|
|
37
|
+
uri.query.include?("num=10").should be_true
|
|
38
|
+
uri.query.include?("daterange:today..+").should be_true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should send valid channel info" do
|
|
42
|
+
uri = URI.parse( Search.construct_url({:channels => ['Running','Triathlon']}) )
|
|
43
|
+
uri.query.include?("meta:channel=Running+OR+meta:channel=Triathlon").should be_true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should send a valid start and end date" do
|
|
47
|
+
uri = URI.parse( Search.construct_url() )
|
|
48
|
+
uri.query.include?("daterange:today..+").should be_true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should send a valid start and end date" do
|
|
52
|
+
uri = URI.parse( Search.construct_url({:start_date => Date.new(2010, 11, 1), :end_date => Date.new(2010, 11, 15)}) )
|
|
53
|
+
uri.query.include?("daterange:11%2F01%2F2010..11%2F15%2F2010").should be_true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should be valid with date range and channels" do
|
|
57
|
+
uri = URI.parse( Search.construct_url({:channels => ['Running','Triathlon'],
|
|
58
|
+
:start_date => Date.new(2010, 11, 1),
|
|
59
|
+
:end_date => Date.new(2010, 11, 15)}) )
|
|
60
|
+
uri.query.include?("meta:channel=Running+OR+meta:channel=Triathlon").should be_true
|
|
61
|
+
uri.query.include?("daterange:11%2F01%2F2010..11%2F15%2F2010").should be_true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
describe Search do
|
|
68
|
+
after(:each) do
|
|
69
|
+
FakeWeb.clean_registry
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# it "should be instantiated without any arguments" do
|
|
73
|
+
# lambda { Search.new( ) }.should raise_error(ArgumentError)
|
|
74
|
+
# lambda { Search.new( "moo" ) }.should_not raise_error
|
|
75
|
+
# end
|
|
76
|
+
|
|
77
|
+
it "should raise and error during a 404" do
|
|
78
|
+
FakeWeb.register_uri(:get, "http://search.active.com/search?api_key=&num=10&page=1&l=San+Diego%2C+CA%2C+US&f=activities&v=json&r=10&s=date_asc&k=&m=daterange:today..+",
|
|
79
|
+
:body => "Nothing to be found 'round here", :status => ["404", "Not Found"])
|
|
80
|
+
lambda { Search.search( {:location => "San Diego, CA, US"} ) }.should raise_error(RuntimeError)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should search by location (san diego)" do
|
|
84
|
+
FakeWeb.register_uri(:get, "http://search.active.com/search?api_key=&num=10&page=1&l=San+Diego%2C+CA%2C+US&f=activities&v=json&r=10&s=date_asc&k=&m=daterange:today..+",
|
|
85
|
+
:body => '{"endIndex":5,"numberOfResults":2,"pageSize":5,"searchTime":0.600205,"_results":[{"escapedUrl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","language": "en","title": "Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","summary": "\u003cb\u003e...\u003c/b\u003e Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs. Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e Recent Reviews Calabasas\u003cbr\u003e Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs reviews. Get Directions. Start Address. End Address \u003cb\u003e...\u003c/b\u003e ","meta": {"startDate": "2010-11-14","eventDate": "2010-11-14T08:00:00-08:00","location": "Calabasas Park Centre","tag": ["event:10", "Green:10", "Running:10"],"state": "California","eventLongitude": "-118.6789","endDate": "2010-11-14","locationName": "Calabasas Park Centre","splitMediaType": ["Event", "1 mile", "10K", "5K"],"endTime": "8:00:00","mediaType": ["Event", "Event\\1 mile", "Event\\10K", "Event\\5K"],"google-site-verification": "","city": "Calabasas","startTime": "8:00:00","assetId": ["11B01475-8C65-4F9C-A4AC-2A3FA55FE8CD", "11b01475-8c65-4f9c-a4ac-2a3fa55fe8cd"],"eventId": "1810531","participationCriteria": "All","description": "","longitude": "-118.6789","onlineDonationAvailable": "false","substitutionUrl": "1810531","assetName": ["Calabasas Classic 2010 - 5k 10k Runs", "Calabasas Classic 2010 - 5k 10k Runs"],"zip": "91302","contactPhone": "818-715-0428","sortDate": "2000-11-14","eventState": "California","eventLatitude": "34.12794","keywords": "Event","eventAddress": "23975 Park Sorrento","contactEmail": "rot10kd@yahoo.com","onlineMembershipAvailable": "false","trackbackurl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://www.active.com/images/events/hotrace.gif","assetTypeId": "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate": "2010-03-04 07:30:26.307","eventZip": "91302","latitude": "34.12794","UpdateDateTime": "8/18/2010 10:16:26 AM","channel": ["Running", "Walking"]}},
|
|
86
|
+
{"escapedUrl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","language": "en","title": "Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10/17, 11/21) \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","summary": "\u003cb\u003e...\u003c/b\u003e Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10/17, 11/21). Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e\u003cbr\u003e Reviews of Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10. \u003cb\u003e...\u003c/b\u003e ","meta": {"summary": "\u003cp style\u003dtext-align:left\u003e\u003cfont style\u003dfont-family:UniversEmbedded;font-size:12;color:#000000; LETTERSPACING\u003d0 KERNING\u003d0\u003eRace or walk on a flat, fast, and fun course! The entire event is along the Puget Sound. Do all 3 events in the series and watch your time and fitness improve! Oatmeal post-race. 10% proceeds sh","startDate": "2010-09-19","eventDate": "2010-09-19","location": "Alki Beach Park, Seattle","tag": ["event:10", "Running:10"],"state": "Washington","endDate": "2010-11-22","locationName": "1702 Alki Ave. SW","splitMediaType": ["5K", "difficulty:Beginner", "difficulty:Advanced", "Event", "difficulty:Intermediate", "10K"],"lastModifiedDateTime": "2010-08-19 23:35:50.117","endTime": "07:59:59","mediaType": ["5K", "difficulty:Beginner", "difficulty:Advanced", "Event", "difficulty:Intermediate", "10K"],"google-site-verification": "","city": "Seattle","startTime": "07:00:00","assetId": ["39e8177e-dd0e-42a2-8a2b-24055e5325f3", "39e8177e-dd0e-42a2-8a2b-24055e5325f3"],"eventId": "E-000NGFS9","participationCriteria": "Kids,Family","description": "","longitude": "-122.3912","substitutionUrl": "E-000NGFS9","assetName": ["Fitness For Vitality 5k/10k 3-Race Series (9/19, 10/17, 11/21)", "Fitness For Vitality 5k/10k 3-Race Series (9/19, 10/17, 11/21)"],"zip": "98136","contactPhone": "n/a","eventState": "WA","sortDate": "2000-09-19","keywords": "Event","eventAddress": "1702 Alki Ave. SW","contactEmail": "n/a","dma": "Seattle - Tacoma","trackbackurl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","seourl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://photos-images.active.com/file/3/1/optimized/9015e50d-3a2e-4ce4-9ddc-80b05b973b01.jpg","allText": "\u003cp style\u003dtext-align:left\u003e\u003cfont style\u003dfont-family:UniversEmbedded;font-size:12;color:#000000; LETTERSPACING\u003d0 KERNING\u003d0\u003eRace or walk on a flat, fast, and fun course! The entire event is along the Puget Sound. Do all 3 events in the series and watch your time and fitness improve! Oatmeal post-race. 10% proceeds sh","address": "1702 Alki Ave. SW","assetTypeId": "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1","lastModifiedDate": "2010-08-19","eventZip": "98136","latitude": "47.53782","UpdateDateTime": "8/18/2010 10:16:08 AM","channel": "Running"}},
|
|
87
|
+
{"escapedUrl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","language": "en","title": "Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","summary": "\u003cb\u003e...\u003c/b\u003e Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs. Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e Recent Reviews Calabasas\u003cbr\u003e Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs reviews. Get Directions. Start Address. End Address \u003cb\u003e...\u003c/b\u003e ","meta": {"startDate": "2010-11-14","eventDate": "2010-11-14T08:00:00-08:00","location": "Calabasas Park Centre","tag": ["event:10", "Green:10", "Running:10"],"state": "California","eventLongitude": "-118.6789","endDate": "2010-11-14","locationName": "Calabasas Park Centre","splitMediaType": ["Event", "1 mile", "10K", "5K"],"endTime": "8:00:00","mediaType": ["Event", "Event\\1 mile", "Event\\10K", "Event\\5K"],"google-site-verification": "","city": "Calabasas","startTime": "8:00:00","assetId": ["11B01475-8C65-4F9C-A4AC-2A3FA55FE8CD", "11b01475-8c65-4f9c-a4ac-2a3fa55fe8cd"],"eventId": "1810531","participationCriteria": "All","description": "","longitude": "-118.6789","onlineDonationAvailable": "false","substitutionUrl": "1810531","assetName": ["Calabasas Classic 2010 - 5k 10k Runs", "Calabasas Classic 2010 - 5k 10k Runs"],"zip": "91302","contactPhone": "818-715-0428","sortDate": "2000-11-14","eventState": "California","eventLatitude": "34.12794","keywords": "Event","eventAddress": "23975 Park Sorrento","contactEmail": "rot10kd@yahoo.com","onlineMembershipAvailable": "false","trackbackurl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://www.active.com/images/events/hotrace.gif","assetTypeId": "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate": "2010-03-04 07:30:26.307","eventZip": "91302","latitude": "34.12794","UpdateDateTime": "8/18/2010 10:16:26 AM","channel": ["Running", "Walking"]}}]}',
|
|
88
|
+
:status => ["200", "Found"])
|
|
89
|
+
results = Search.search( {:location => "San Diego, CA, US"} )
|
|
90
|
+
results.should have(3).items
|
|
91
|
+
results.each do |a|
|
|
92
|
+
a.should be_an_instance_of(Activity)
|
|
93
|
+
a.title.should_not be_nil
|
|
94
|
+
a.start_date.should_not be_nil
|
|
95
|
+
a.end_date.should_not be_nil
|
|
96
|
+
a.category.should_not be_nil
|
|
97
|
+
a.desc.should_not be_nil
|
|
98
|
+
a.start_time.should_not be_nil
|
|
99
|
+
a.end_time.should_not be_nil
|
|
100
|
+
a.address.should_not be_nil
|
|
101
|
+
a.address[:name].should_not be_nil
|
|
102
|
+
a.address[:city].should_not be_nil
|
|
103
|
+
a.address[:state].should_not be_nil
|
|
104
|
+
a.address[:zip].should_not be_nil
|
|
105
|
+
a.address[:country].should_not be_nil
|
|
106
|
+
a.address[:lat].should_not be_nil
|
|
107
|
+
a.address[:lng].should_not be_nil
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib Active]))
|
|
3
|
+
|
|
4
|
+
Spec::Runner.configure do |config|
|
|
5
|
+
# == Mock Framework
|
|
6
|
+
#
|
|
7
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
|
8
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
|
9
|
+
#
|
|
10
|
+
# config.mock_with :mocha
|
|
11
|
+
# config.mock_with :flexmock
|
|
12
|
+
# config.mock_with :rr
|
|
13
|
+
end
|
|
14
|
+
|
data/test/test_Active.rb
ADDED
|
File without changes
|
data/version.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.1
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Active
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Jonathan Spooner, Brian Levine
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-08-31 00:00:00 -07:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: bones
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 25
|
|
30
|
+
segments:
|
|
31
|
+
- 3
|
|
32
|
+
- 4
|
|
33
|
+
- 7
|
|
34
|
+
version: 3.4.7
|
|
35
|
+
type: :development
|
|
36
|
+
version_requirements: *id001
|
|
37
|
+
description: Search api for Active Network
|
|
38
|
+
email: jspooner [at] gmail.com
|
|
39
|
+
executables:
|
|
40
|
+
- Active
|
|
41
|
+
extensions: []
|
|
42
|
+
|
|
43
|
+
extra_rdoc_files:
|
|
44
|
+
- History.txt
|
|
45
|
+
- README.txt
|
|
46
|
+
- bin/Active
|
|
47
|
+
- version.txt
|
|
48
|
+
files:
|
|
49
|
+
- .DS_Store
|
|
50
|
+
- .bnsignore
|
|
51
|
+
- Active-0.0.0.gem
|
|
52
|
+
- Active.gemspec
|
|
53
|
+
- History.txt
|
|
54
|
+
- README.txt
|
|
55
|
+
- Rakefile
|
|
56
|
+
- bin/Active
|
|
57
|
+
- lib/Active.rb
|
|
58
|
+
- lib/services/activity.rb
|
|
59
|
+
- lib/services/search.rb
|
|
60
|
+
- spec/.DS_Store
|
|
61
|
+
- spec/Active_spec.rb
|
|
62
|
+
- spec/activity_spec.rb
|
|
63
|
+
- spec/search_spec.rb
|
|
64
|
+
- spec/spec_helper.rb
|
|
65
|
+
- test/test_Active.rb
|
|
66
|
+
- version.txt
|
|
67
|
+
has_rdoc: true
|
|
68
|
+
homepage: http://developer.active.com/docs/Activecom_Search_API_Reference
|
|
69
|
+
licenses: []
|
|
70
|
+
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options:
|
|
73
|
+
- --main
|
|
74
|
+
- README.txt
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
none: false
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
hash: 3
|
|
83
|
+
segments:
|
|
84
|
+
- 0
|
|
85
|
+
version: "0"
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
none: false
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
hash: 3
|
|
92
|
+
segments:
|
|
93
|
+
- 0
|
|
94
|
+
version: "0"
|
|
95
|
+
requirements: []
|
|
96
|
+
|
|
97
|
+
rubyforge_project: Active
|
|
98
|
+
rubygems_version: 1.3.7
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 3
|
|
101
|
+
summary: Search api for Active Network
|
|
102
|
+
test_files:
|
|
103
|
+
- test/test_Active.rb
|