Module: ImageSearcher
- Extended by:
- Filter
- Defined in:
- lib/image_searcher.rb,
lib/image_searcher/api.rb,
lib/image_searcher/search.rb,
lib/image_searcher/version.rb
Defined Under Namespace
Modules: API, Filter
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Methods included from Filter
filter_by_format, filter_by_formats
Class Method Details
.build_json_url(options) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/image_searcher/search.rb', line 19
def self.build_json_url(options)
base_uri = ImageSearcher::API::BASE_URI
url = "#{base_uri}?q=#{options[:query]}"
url += "&count=#{options[:count]}" if options[:count]
url
end
|
26
27
28
29
30
31
32
33
34
|
# File 'lib/image_searcher/search.rb', line 26
def self.perform_filter_params(result, options)
if options[:format]
result = filter_by_format(result, options[:format])
end
if options[:formats]
result = filter_by_formats(result, options[:formats])
end
end
|
.raise_errors(options) ⇒ Object
14
15
16
17
|
# File 'lib/image_searcher/search.rb', line 14
def self.raise_errors(options)
raise "Missing params" if options[:query].nil?
raise "Missing query" if options[:query].empty?
end
|
.search(options = {}) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/image_searcher/search.rb', line 6
def self.search(options = {})
raise_errors(options)
url = build_json_url(options)
result = ImageSearcher::API.get_json(url)
perform_filter_params(result, options)
result
end
|