65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/services/search.rb', line 65
def self.construct_url(arg_options={})
options = {
:api_key => "",
:view => "json",
:facet => Facet.ACTIVITIES,
:sort => Sort.DATE_ASC,
:radius => "10",
:meta => "",
:num_results => "10",
:page => "1",
:location => "",
:search => "",
:keywords => [],
:channels => nil,
:start_date => "today",
:end_date => "+"
}
options.merge!(arg_options)
options[:location] = CGI.escape(options[:location]) if options[:location]
if options[:keywords].class == String
options[:keywords] = options[:keywords].split(",")
options[:keywords].each { |k| k.strip! }
end
channels_str = ""
if options[:channels] != nil
channels_a = options[:channels].collect { |channel|
"meta:channel=#{URI.escape(URI.escape(channel, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")),Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")).gsub(/\-/,"%252D")}"
}
end
meta_data = ""
meta_data = channels_a.join("+OR+") if channels_a
meta_data += "+AND+" unless meta_data == ""
if options[:start_date].class == Date
options[:start_date] = URI.escape(options[:start_date].strftime("%m/%d/%Y")).gsub(/\//,"%2F")
end
if options[:end_date].class == Date
options[:end_date] = URI.escape(options[:end_date].strftime("%m/%d/%Y")).gsub(/\//,"%2F")
end
meta_data += "meta:startDate:daterange:#{options[:start_date]}..#{options[:end_date]}"
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}"
puts url
url
end
|