Class: Active::Services::Search
- Inherits:
-
Object
- Object
- Active::Services::Search
- Defined in:
- lib/services/search.rb
Constant Summary collapse
- SEARCH_URL =
"http://search.active.com"
- DEFAULT_TIMEOUT =
60
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#asset_ids ⇒ Object
Returns the value of attribute asset_ids.
-
#asset_type_id ⇒ Object
Returns the value of attribute asset_type_id.
-
#bounding_box ⇒ Object
Returns the value of attribute bounding_box.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#dma ⇒ Object
Returns the value of attribute dma.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#end_point ⇒ Object
readonly
Returns the value of attribute end_point.
-
#endIndex ⇒ Object
readonly
Returns the value of attribute endIndex.
-
#facet ⇒ Object
Returns the value of attribute facet.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#location ⇒ Object
Returns the value of attribute location.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#num_results ⇒ Object
Returns the value of attribute num_results.
-
#numberOfResults ⇒ Object
readonly
Returns the value of attribute numberOfResults.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#page ⇒ Object
Returns the value of attribute page.
-
#pageSize ⇒ Object
readonly
Returns the value of attribute pageSize.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#search ⇒ Object
TODO the seach method should not raise an error.
-
#searchTime ⇒ Object
readonly
Returns the value of attribute searchTime.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#split_media_type ⇒ Object
Returns the value of attribute split_media_type.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#state ⇒ Object
Returns the value of attribute state.
-
#url ⇒ Object
Returns the value of attribute url.
-
#view ⇒ Object
Returns the value of attribute view.
Class Method Summary collapse
Instance Method Summary collapse
- #[] ⇒ Object
- #asset_id=(value) ⇒ Object
-
#initialize(data = {}) ⇒ Search
constructor
A new instance of Search.
- #zips ⇒ Object
-
#zips=(value) ⇒ Object
Example Search.search( => “92121, 92078, 92114” ) or Search.new( => [92121, 92078, 92114] ).
Constructor Details
#initialize(data = {}) ⇒ Search
Returns a new instance of Search.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/services/search.rb', line 41 def initialize(data={}) self.asset_type_id = data[:asset_type_id] self.url = data[:url] self.api_key = data[:api_key] || "" self.location = data[:location] self.zips = data[:zips] || [] self.channels = data[:channels] || [] self.split_media_type = data[:split_media_type] || [] self.keywords = data[:keywords] || [] self.radius = data[:radius] || nil self.limit = data[:limit] || "10" self.sort = data[:sort] || Sort.DATE_ASC self.page = data[:page] || "1" self.offset = data[:offset] || "0" self.view = data[:view] || "json" self.facet = data[:facet] || Facet.ACTIVITIES self.num_results = data[:num_results] || "10" self.search = data[:search] || "" self.start_date = data[:start_date] || "today" self.end_date = data[:end_date] || "+" self.asset_ids = data[:asset_ids] || [] self.asset_id = data[:asset_id] || "" self.latitude = data[:latitude] self.longitude = data[:longitude] self.dma = data[:dma] self.city = data[:city] self.state = data[:state] self.country = data[:country] self.bounding_box = data[:bounding_box] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
32 33 34 |
# File 'lib/services/search.rb', line 32 def api_key @api_key end |
#asset_ids ⇒ Object
Returns the value of attribute asset_ids.
32 33 34 |
# File 'lib/services/search.rb', line 32 def asset_ids @asset_ids end |
#asset_type_id ⇒ Object
Returns the value of attribute asset_type_id.
32 33 34 |
# File 'lib/services/search.rb', line 32 def asset_type_id @asset_type_id end |
#bounding_box ⇒ Object
Returns the value of attribute bounding_box.
32 33 34 |
# File 'lib/services/search.rb', line 32 def bounding_box @bounding_box end |
#channels ⇒ Object
Returns the value of attribute channels.
32 33 34 |
# File 'lib/services/search.rb', line 32 def channels @channels end |
#city ⇒ Object
Returns the value of attribute city.
32 33 34 |
# File 'lib/services/search.rb', line 32 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
32 33 34 |
# File 'lib/services/search.rb', line 32 def country @country end |
#dma ⇒ Object
Returns the value of attribute dma.
32 33 34 |
# File 'lib/services/search.rb', line 32 def dma @dma end |
#end_date ⇒ Object
Returns the value of attribute end_date.
32 33 34 |
# File 'lib/services/search.rb', line 32 def end_date @end_date end |
#end_point ⇒ Object (readonly)
Returns the value of attribute end_point.
36 37 38 |
# File 'lib/services/search.rb', line 36 def end_point @end_point end |
#endIndex ⇒ Object (readonly)
Returns the value of attribute endIndex.
36 37 38 |
# File 'lib/services/search.rb', line 36 def endIndex @endIndex end |
#facet ⇒ Object
Returns the value of attribute facet.
32 33 34 |
# File 'lib/services/search.rb', line 32 def facet @facet end |
#keywords ⇒ Object
Returns the value of attribute keywords.
32 33 34 |
# File 'lib/services/search.rb', line 32 def keywords @keywords end |
#latitude ⇒ Object
Returns the value of attribute latitude.
32 33 34 |
# File 'lib/services/search.rb', line 32 def latitude @latitude end |
#limit ⇒ Object
Returns the value of attribute limit.
32 33 34 |
# File 'lib/services/search.rb', line 32 def limit @limit end |
#location ⇒ Object
Returns the value of attribute location.
32 33 34 |
# File 'lib/services/search.rb', line 32 def location @location end |
#longitude ⇒ Object
Returns the value of attribute longitude.
32 33 34 |
# File 'lib/services/search.rb', line 32 def longitude @longitude end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
36 37 38 |
# File 'lib/services/search.rb', line 36 def @meta end |
#num_results ⇒ Object
Returns the value of attribute num_results.
32 33 34 |
# File 'lib/services/search.rb', line 32 def num_results @num_results end |
#numberOfResults ⇒ Object (readonly)
Returns the value of attribute numberOfResults.
36 37 38 |
# File 'lib/services/search.rb', line 36 def numberOfResults @numberOfResults end |
#offset ⇒ Object
Returns the value of attribute offset.
32 33 34 |
# File 'lib/services/search.rb', line 32 def offset @offset end |
#page ⇒ Object
Returns the value of attribute page.
32 33 34 |
# File 'lib/services/search.rb', line 32 def page @page end |
#pageSize ⇒ Object (readonly)
Returns the value of attribute pageSize.
36 37 38 |
# File 'lib/services/search.rb', line 36 def pageSize @pageSize end |
#radius ⇒ Object
Returns the value of attribute radius.
32 33 34 |
# File 'lib/services/search.rb', line 32 def radius @radius end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
36 37 38 |
# File 'lib/services/search.rb', line 36 def results @results end |
#search ⇒ Object
TODO the seach method should not raise an error.
244 245 246 |
# File 'lib/services/search.rb', line 244 def search @search end |
#searchTime ⇒ Object (readonly)
Returns the value of attribute searchTime.
36 37 38 |
# File 'lib/services/search.rb', line 36 def searchTime @searchTime end |
#sort ⇒ Object
Returns the value of attribute sort.
32 33 34 |
# File 'lib/services/search.rb', line 32 def sort @sort end |
#split_media_type ⇒ Object
Returns the value of attribute split_media_type.
32 33 34 |
# File 'lib/services/search.rb', line 32 def split_media_type @split_media_type end |
#start_date ⇒ Object
Returns the value of attribute start_date.
32 33 34 |
# File 'lib/services/search.rb', line 32 def start_date @start_date end |
#state ⇒ Object
Returns the value of attribute state.
32 33 34 |
# File 'lib/services/search.rb', line 32 def state @state end |
#url ⇒ Object
Returns the value of attribute url.
32 33 34 |
# File 'lib/services/search.rb', line 32 def url @url end |
#view ⇒ Object
Returns the value of attribute view.
32 33 34 |
# File 'lib/services/search.rb', line 32 def view @view end |
Class Method Details
.return_cached(key) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/services/search.rb', line 332 def self.return_cached key if Active.CACHE begin cached_version = Active.CACHE.get(key) rescue Exception => e return nil end if cached_version puts "Active Search [CACHE] #{key}" return cached_version end end nil end |
.search(data = nil) ⇒ Object
examples
Keywords =
Keywords can be set like this Search.new(=> “Dog,Cat,Cow”) Search.new(=> %w(Dog Cat Cow)) Search.new(=> [“Dog”,“Cat”,“Cow”])
Channels and MediaType =
Search.new(=> [:running], :split_media_type => [“5k”]) for a list of channels and splitMediaTypes please see developer.active.com/docs/Activecom_Search_API_Reference
Location =
The location will be set in this order and will override other values. For example is you set a zip code and a location only the zip will be used.
1 Look for zip codes
Search.search( {:zips => "92121, 92078, 92114"} )
Search.search( {:zips => %w(92121, 92078, 92114)} )
Search.search( {:zips => [92121, 92078, 92114]} )
2 Look for lat lng
Search.search( {:latitude=>"37.785895", :longitude=>"-122.40638"} )
3 Look for a formatted string “San Diego, CA, US”
Search.search( {:location = "San Diego, CA, US"} )
4 Look for a DMA
Search.new({:dma=>"San Francisco - Oakland - San Jose"})
How to look at the results =
developer.active.com/docs/Activecom_Search_API_Reference returns an array of results and query info
319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/services/search.rb', line 319 def self.search(data=nil) search = Search.new(data) search_hash = Digest::MD5.hexdigest(search.end_point) puts "search_hash #{search_hash}" cache = Search.return_cached(search_hash) if cache != nil return cache else search.search return search end end |
Instance Method Details
#[] ⇒ Object
351 352 353 |
# File 'lib/services/search.rb', line 351 def [] @results end |
#asset_id=(value) ⇒ Object
123 124 125 126 |
# File 'lib/services/search.rb', line 123 def asset_id=(value) return if value.empty? @asset_ids<<value end |
#zips ⇒ Object
84 85 86 |
# File 'lib/services/search.rb', line 84 def zips @zips end |
#zips=(value) ⇒ Object
Example Search.search( => “92121, 92078, 92114” ) or Search.new( => [92121, 92078, 92114] )
76 77 78 79 80 81 82 |
# File 'lib/services/search.rb', line 76 def zips=(value) if value.class == String @zips = value.split(",").each { |k| k.strip! } else @zips = value end end |