Active 0.0.32 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
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
19
+ .DS_Store
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Bones {
18
18
  Welcome to Active Network
19
19
  --------------------------
20
20
  MSG
21
- depend_on 'savon'
21
+ depend_on 'savon', '0.7.9'
22
22
  depend_on 'dalli', '0.9.8'
23
23
  }
24
24
 
data/bin/Active CHANGED
File without changes
@@ -6,6 +6,8 @@ module Active
6
6
  class GSA < IActivity
7
7
  require 'nokogiri'
8
8
  require 'open-uri'
9
+ # require 'active_support/core_ext/hash/'
10
+
9
11
  attr_accessor :asset_type_id
10
12
 
11
13
  # EXAMPLE Data hash
@@ -14,6 +16,7 @@ module Active
14
16
  def initialize(json={})
15
17
  # need to hold on to original data
16
18
  @data = HashWithIndifferentAccess.new(json) || HashWithIndifferentAccess.new
19
+ # @data = HashWithIndifferentAccess.new(json) || HashWithIndifferentAccess.new
17
20
  # self.title = @data['meta']['assetName'] || nil
18
21
  self.title = @data['title'] || nil
19
22
  end
@@ -30,6 +30,7 @@ module Active
30
30
 
31
31
  class Search
32
32
  attr_accessor :api_key, :start_date, :end_date, :location, :channels, :split_media_type, :keywords, :search, :radius, :limit, :sort, :page, :offset, :latitude, :longitude,
33
+ :asset_type_id, :url,
33
34
  :view, :facet, :sort, :num_results, :asset_ids, :dma, :city, :state, :country, :bounding_box
34
35
 
35
36
  attr_reader :results, :endIndex, :pageSize, :searchTime, :numberOfResults, :end_point, :meta
@@ -38,32 +39,34 @@ module Active
38
39
  DEFAULT_TIMEOUT = 60
39
40
 
40
41
  def initialize(data={})
41
- self.api_key = data[:api_key] || ""
42
- self.location = data[:location]
43
- self.zips = data[:zips] || []
44
- self.channels = data[:channels] || []
45
- self.split_media_type= data[:split_media_type] || []
46
- self.keywords = data[:keywords] || []
47
- self.radius = data[:radius] || nil
48
- self.limit = data[:limit] || "10"
49
- self.sort = data[:sort] || Sort.DATE_ASC
50
- self.page = data[:page] || "1"
51
- self.offset = data[:offset] || "0"
52
- self.view = data[:view] || "json"
53
- self.facet = data[:facet] || Facet.ACTIVITIES
54
- self.num_results = data[:num_results] || "10"
55
- self.search = data[:search] || ""
56
- self.start_date = data[:start_date] || "today"
57
- self.end_date = data[:end_date] || "+"
58
- self.asset_ids = data[:asset_ids] || []
59
- self.asset_id = data[:asset_id] || ""
60
- self.latitude = data[:latitude]
61
- self.longitude = data[:longitude]
62
- self.dma = data[:dma]
63
- self.city = data[:city]
64
- self.state = data[:state]
65
- self.country = data[:country]
66
- self.bounding_box = data[:bounding_box]
42
+ self.asset_type_id = data[:asset_type_id]
43
+ self.url = data[:url]
44
+ self.api_key = data[:api_key] || ""
45
+ self.location = data[:location]
46
+ self.zips = data[:zips] || []
47
+ self.channels = data[:channels] || []
48
+ self.split_media_type = data[:split_media_type] || []
49
+ self.keywords = data[:keywords] || []
50
+ self.radius = data[:radius] || nil
51
+ self.limit = data[:limit] || "10"
52
+ self.sort = data[:sort] || Sort.DATE_ASC
53
+ self.page = data[:page] || "1"
54
+ self.offset = data[:offset] || "0"
55
+ self.view = data[:view] || "json"
56
+ self.facet = data[:facet] || Facet.ACTIVITIES
57
+ self.num_results = data[:num_results] || "10"
58
+ self.search = data[:search] || ""
59
+ self.start_date = data[:start_date] || "today"
60
+ self.end_date = data[:end_date] || "+"
61
+ self.asset_ids = data[:asset_ids] || []
62
+ self.asset_id = data[:asset_id] || ""
63
+ self.latitude = data[:latitude]
64
+ self.longitude = data[:longitude]
65
+ self.dma = data[:dma]
66
+ self.city = data[:city]
67
+ self.state = data[:state]
68
+ self.country = data[:country]
69
+ self.bounding_box = data[:bounding_box]
67
70
  end
68
71
 
69
72
  # Example
@@ -128,14 +131,33 @@ module Active
128
131
  # CHANNELS
129
132
  channel_keys = []
130
133
  @channels.each do |c|
131
- c.to_sym
134
+ c = c.to_sym
132
135
  if Categories.CHANNELS.include?(c)
133
136
  channel_keys << Categories.CHANNELS[c]
137
+ else
138
+ puts "/////////// Channel key not found [#{c}]"
134
139
  end
135
140
  end
136
- meta_data = channel_keys.collect { |channel| "meta:channel=#{Search.double_encode_channel(channel)}" }.join("+OR+")
141
+ meta_data += channel_keys.collect { |channel| "meta:channel=#{Search.double_encode_channel(channel)}" }.join("+OR+")
137
142
  # SPLIT MEDIA TYPE
138
- meta_data += split_media_type.collect { |type| "+meta:splitMediaType=#{Search.double_encode_channel(type)}" }.join("+OR+") unless split_media_type.nil?
143
+ if split_media_type
144
+ meta_data += "+AND+" unless meta_data == ""
145
+ meta_data += split_media_type.collect { |type| "meta:splitMediaType=#{Search.double_encode_channel(type)}" }.join("+OR+")
146
+ end
147
+ # ASSET TYPE ID
148
+ if asset_type_id
149
+ meta_data += "+AND+" unless meta_data == ""
150
+ meta_data += "meta:assetTypeId=#{Search.double_encode_channel(asset_type_id)}"
151
+ end
152
+ # url
153
+ if url
154
+ meta_data += "+AND+" unless meta_data == ""
155
+ # url.gsub!(/\-/,"%252D")
156
+ url.gsub!(/\//,"%2F")
157
+ # URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
158
+ meta_data += "site:#{url}"
159
+ # meta_data += "site:#{Search.double_encode_channel(url)}"
160
+ end
139
161
  # ASSET IDS
140
162
  unless asset_ids.empty?
141
163
  meta_data += "+AND+" unless meta_data == ""
@@ -154,42 +176,28 @@ module Active
154
176
  if @city or @state or @country
155
177
  if @city
156
178
  meta_data += "+AND+" unless meta_data == ""
157
- meta_data += "meta:city=#{Search.double_encode_channel(@city)}"
179
+ meta_data += "meta:city=#{Search.double_encode_channel(@city)}"
158
180
  end
159
181
  if @state
160
182
  meta_data += "+AND+" unless meta_data == ""
161
- meta_data += "meta:state=#{Search.double_encode_channel(@state)}"
183
+ meta_data += "meta:state=#{Search.double_encode_channel(@state)}"
162
184
  end
163
185
  elsif !@zips.empty?
164
- # if not @zips.empty?
165
186
  loc_str = @zips.join(",")
166
187
  elsif @latitude and @longitude
167
188
  loc_str = "#{@latitude};#{@longitude}"
168
189
  elsif @dma
169
-
170
190
  meta_data += "+AND+" unless meta_data == ""
171
191
  meta_data += "meta:dma=#{Search.double_encode_channel(@dma)}"
172
192
  else
173
193
  loc_str = @location
174
194
  end
175
195
 
176
-
177
- # AND DATE
178
- meta_data += "+AND+" unless meta_data == ""
179
- if @start_date.class == Date
180
- @start_date = URI.escape(@start_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
181
- end
182
- if @end_date.class == Date
183
- @end_date = URI.escape(@end_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
184
- end
185
- meta_data += "meta:startDate:daterange:#{@start_date}..#{@end_date}"
186
-
187
196
  # BOUNDING BOX
188
- if @bounding_box!=nil
197
+ unless @bounding_box.nil?
189
198
  #The values in the GSA metadata are shifted to prevent negative values. This was done b/c lat/long
190
199
  # are searched as a number range and the GSA doesn't allow negative values in number ranges.
191
200
  # We shift latitude values by 90 and longitude values by 180.
192
-
193
201
  if @bounding_box[:sw].class==String
194
202
  #String :bounding_box => { :sw => "37.695141,-123.013657", :ne => "37.832371,-122.356979"}
195
203
  latitude1 = @bounding_box[:sw].split(",").first.to_f+90
@@ -205,8 +213,18 @@ module Active
205
213
  end
206
214
  meta_data += "+AND+" unless meta_data == ""
207
215
  meta_data += "meta:latitudeShifted:#{latitude1}..#{latitude2}+AND+meta:longitudeShifted:#{longitude1}..#{longitude2}"
208
- end
216
+ end
209
217
 
218
+ # AND DATE
219
+ if @start_date.class == Date
220
+ @start_date = URI.escape(@start_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
221
+ end
222
+ if @end_date.class == Date
223
+ @end_date = URI.escape(@end_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
224
+ end
225
+ meta_data += "+AND+" unless meta_data == ""
226
+ meta_data += "meta:startDate:daterange:#{@start_date}..#{@end_date}"
227
+
210
228
  # url = "#{SEARCH_URL}/search?api_key=#{@api_key}&num=#{@num_results}&page=#{@page}&l=#{loc_str}&f=#{@facet}&v=#{@view}&r=#{@radius}&s=#{@sort}&k=#{@keywords.join("+")}&m=#{meta_data}"
211
229
  urla = ["#{SEARCH_URL}/search?api_key=#{@api_key}"]
212
230
  urla << "num=#{@num_results}" if @num_results
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib Active]))
3
2
  include Active::Services
4
3
 
@@ -25,4 +24,23 @@ include Active::Services
25
24
  # puts " "
26
25
  # puts arr
27
26
 
28
- puts Search.search(:asset_ids => ["DD8F427F-6188-465B-8C26-71BBA22D2DB7"]).results.inspect
27
+ # puts Search.search(:asset_ids => ["DD8F427F-6188-465B-8C26-71BBA22D2DB7"]).results.inspect
28
+
29
+ REG_CENTER_ASSET_TYPE_ID = "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
30
+ REG_CENTER_ASSET_TYPE_ID2 = "3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6"
31
+ ACTIVE_WORKS_ASSET_TYPE_ID = "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
32
+
33
+ local_asset_type_id = "EC6E96A5-6900-4A0E-8B83-9AA935F45A73"
34
+ puts "Local " + Search.search({:asset_type_id => local_asset_type_id}).results.length.to_s
35
+ puts "Local " + Search.search({:asset_type_id => local_asset_type_id, :start_date => Date.new(2010, 1, 1), :end_date => Date.new(2011, 11, 15) }).results.length.to_s
36
+ # puts "ActiveWorks " + Search.search({:asset_type_id => ACTIVE_WORKS_ASSET_TYPE_ID, :start_date => Date.new(2010, 1, 1), :end_date => Date.new(2011, 11, 15) }).results.length.to_s
37
+
38
+ # url = "www.active.com/running/long-branch-nj/new-jersey-marathon-and-long-branch-half-marathon-2011"
39
+ # r = Search.search({:url => url}).results # , :start_date => Date.new(2011, 1, 1), :end_date => Date.new(2012, 1, 15)
40
+ # puts url
41
+ # puts "Results: #{r.length}"
42
+ # puts r.map(&:url)
43
+
44
+
45
+ # r = Search.search({:dma=>"San Francisco - Oakland - San Jose", :num_results => 5}).results
46
+ # puts r.map(&:url)
@@ -67,6 +67,9 @@ describe Search do
67
67
  s = Search.new()
68
68
  s.should have(0).channels
69
69
  s = Search.new({:channels => "running,swimming,yoga"})
70
+ puts s.end_point
71
+ s.end_point.include?("m=meta:channel=Running+OR+meta:channel=Swimming+OR+meta:channel=Mind%2520%2526%2520Body%255CYoga").should be_true
72
+
70
73
  s.should have(3).channels
71
74
  s = Search.new({:channels => %w(running swimming yoga)})
72
75
  s.should have(3).channels
@@ -127,6 +130,17 @@ describe Search do
127
130
  uri.query.include?("meta:channel=Running+OR+meta:channel=Triathlon").should be_true
128
131
  end
129
132
 
133
+ it "should send valid channel info and a bounding_box" do
134
+ s = Search.new({:bounding_box => { :sw => "37.695141,-123.013657", :ne => "37.695141,-123.013657"}, :channels => [:running,:triathlon] })
135
+ s.bounding_box.should_not be_nil
136
+ # uri = URI.parse( Search.new({:channels => [:running,:triathlon], :bounding_box => { :sw => "37.695141,-123.013657", :ne => "37.695141,-123.013657"} }).end_point )
137
+ uri = URI.parse( s.end_point )
138
+ puts "????????????????????? "
139
+ puts uri
140
+ uri.query.include?("meta:channel=Running+OR+meta:channel=Triathlon").should be_true
141
+ uri.query.include?("meta:latitudeShifted:127.695141..127.695141+AND+meta:longitudeShifted:56.986343..56.986343").should be_true
142
+ end
143
+
130
144
  it "should send the correct channel value for everything in Search.CHANNELS" do
131
145
  Categories.CHANNELS.each do |key,value|
132
146
  uri = URI.parse( Search.new({:channels => [key]}).end_point )
@@ -146,6 +160,20 @@ describe Search do
146
160
  # SHOULD NOT SEE "++"
147
161
  pending
148
162
  end
163
+
164
+ it "should pass the assetTypeId" do
165
+ local_asset_type_id = "EC6E96A5-6900-4A0E-8B83-9AA935F45A73"
166
+ encoded = "EC6E96A5%252D6900%252D4A0E%252D8B83%252D9AA935F45A73"
167
+ uri = URI.parse( Search.new({:asset_type_id => local_asset_type_id}).end_point )
168
+ uri.query.should have_param("meta:assetTypeId=#{encoded}")
169
+ end
170
+
171
+ it "should pass a url" do
172
+ url = "www.active.com/running/pleasant-hill-ca/dont-wine-just-run-5k-fun-runwalk-east-bay-edition-2011"
173
+ encoded = "site:www.active.com%2Frunning%2Flong-branch-nj%2Fnew-jersey-marathon-and-long-branch-half-marathon-2011"
174
+ uri = URI.parse( Search.new({:url => url}).end_point )
175
+ uri.query.should have_param(encoded)
176
+ end
149
177
 
150
178
  it "should send a valid start and end date" do
151
179
  uri = URI.parse( Search.new().end_point )
@@ -205,10 +233,12 @@ describe Search do
205
233
  end
206
234
 
207
235
  it "should find 5 items when doing a DMA search" do
208
- Search.search({:dma=>"San Francisco - Oakland - San Jose", :limit => 5}).should have(5).results
209
- Search.search({:dma=>"San Francisco - Oakland - San Jose", :limit => 2}).should have(2).results
236
+ Search.new({:dma=>"San Francisco - Oakland - San Jose", :num_results => 5}).num_results.should eql(5)
237
+ Search.search({:dma=>"San Francisco - Oakland - San Jose", :num_results => 5}).should have(5).results
238
+ Search.search({:dma=>"San Francisco - Oakland - San Jose", :num_results => 2}).should have(2).results
210
239
  end
211
240
  end
241
+
212
242
  describe "Handle http server codes" do
213
243
  after(:each) do
214
244
  FakeWeb.clean_registry
@@ -385,18 +415,17 @@ describe Search do
385
415
  s = Search.search( {:sort=>Sort.DATE_DESC})
386
416
  s.should be_an_instance_of Search
387
417
  s.results.should_not be_empty
388
- s.results.each do |a|
389
- DateTime.parse(a.gsa.last_modified).should satisfy { |d|
390
- d >= DateTime.now-2
391
- }
392
- end
418
+ # s.results.each do |a|
419
+ # DateTime.parse(a.gsa.last_modified).should satisfy { |d|
420
+ # d >= DateTime.now-2
421
+ # }
422
+ # end
393
423
  end
394
424
  it "should find events that have online regristration"
395
425
  it "should find events that do not have online regristration"
396
426
 
397
427
  it "should have a nil email address from GSA" do
398
428
  Search.search(:asset_id => "715ED4EF-E4FF-42F2-B24B-2E4255649676").results.first.user.email.should be_nil
399
- # first.address["address"].should_not be_nil
400
429
  end
401
430
 
402
431
  end
@@ -404,24 +433,16 @@ describe Search do
404
433
  describe "Parametric search for running channel" do
405
434
  it "should find by splitMediaType for the Running channel" do
406
435
  # http://developer.active.com/docs/Activecom_Search_API_Reference
436
+ s = Search.search({:channels => [:running], :split_media_type => ["5K"]})
437
+ s.results.each do |result|
438
+ result.gsa.data['meta']['splitMediaType'].should include("5K")
439
+ end
440
+
407
441
  end
408
442
  end
409
443
  describe "Parametric search for triathlon channel" do
410
444
  end
411
445
  end
412
-
413
- describe "Find things within X miles to me" do
414
- it "should find activities within 20 miles of me" do
415
- location = {:latitude=>"37.785895", :longitude=>"-122.40638"}
416
- Search.search(location).results.should_not be_empty
417
- pending
418
- end
419
- end
420
-
421
- # describe "Finding assets via a url only" do
422
- # it "should find an asset by seourl" do
423
- # end
424
- # end
425
446
 
426
447
  end
427
448
 
File without changes
@@ -16,10 +16,4 @@ describe Validators do
16
16
  Validators.email("jspooner@ga").should be_false
17
17
  end
18
18
 
19
- end
20
-
21
-
22
-
23
-
24
-
25
-
19
+ end
@@ -1 +1 @@
1
- 0.0.32
1
+ 0.0.34
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Active
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 91
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 32
9
- version: 0.0.32
9
+ - 34
10
+ version: 0.0.34
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jonathan Spooner, Brian Levine
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-03 00:00:00 -08:00
18
+ date: 2011-01-10 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: savon
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 17
27
30
  segments:
28
31
  - 0
29
32
  - 7
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: dalli
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 43
41
46
  segments:
42
47
  - 0
43
48
  - 9
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: bones
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 25
55
62
  segments:
56
63
  - 3
57
64
  - 4
@@ -69,19 +76,16 @@ extra_rdoc_files:
69
76
  - History.txt
70
77
  - README.txt
71
78
  - bin/Active
72
- - lib/.DS_Store
73
- - lib/services/.DS_Store
74
79
  - lib/services/search.txt
75
80
  - version.txt
76
81
  files:
82
+ - .bnsignore
77
83
  - Active.gemspec
78
84
  - History.txt
79
85
  - README.txt
80
86
  - Rakefile
81
87
  - bin/Active
82
- - lib/.DS_Store
83
88
  - lib/Active.rb
84
- - lib/services/.DS_Store
85
89
  - lib/services/IActivity.rb
86
90
  - lib/services/_ats.rb
87
91
  - lib/services/active_works.rb
@@ -124,23 +128,27 @@ rdoc_options:
124
128
  require_paths:
125
129
  - lib
126
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
127
132
  requirements:
128
133
  - - ">="
129
134
  - !ruby/object:Gem::Version
135
+ hash: 3
130
136
  segments:
131
137
  - 0
132
138
  version: "0"
133
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
134
141
  requirements:
135
142
  - - ">="
136
143
  - !ruby/object:Gem::Version
144
+ hash: 3
137
145
  segments:
138
146
  - 0
139
147
  version: "0"
140
148
  requirements: []
141
149
 
142
150
  rubyforge_project: Active
143
- rubygems_version: 1.3.6
151
+ rubygems_version: 1.3.7
144
152
  signing_key:
145
153
  specification_version: 3
146
154
  summary: Search api for Active Network
Binary file
Binary file