image_searcher 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/image_searcher.gemspec +3 -3
- data/lib/image_searcher.rb +1 -1
- data/lib/image_searcher/client.rb +41 -0
- metadata +10 -11
- data/lib/image_searcher/filter.rb +0 -14
- data/lib/image_searcher/search.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0fbd835cba4e16b93ff11774c9fc7070bd7fe94
|
4
|
+
data.tar.gz: 13ac2936185dd3407597a4b6f69338cc5e874c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca84b4b6c8ea47b932096d32e3878dd9f368da87671489cb2c019cc4ddd1ff4e03beb2c780fe38fae2d8b95f7d804b4d6e15a49e8d4b8bf656b9eff70797f57b
|
7
|
+
data.tar.gz: 6e3277be60e90c12d5d254227b6b051c1b0063be4f26cb300ecea19130ad0d37adcdce108d6c7e1d44dc1f4760743d1a5a3b693720b66e0e8337cb04119bdef1
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ And you've got an array of objects. By default the result has `100` nested array
|
|
29
29
|
**Available options**:
|
30
30
|
```
|
31
31
|
query(String)
|
32
|
-
count(Integer) - maximum 100(
|
32
|
+
count(Integer) - maximum 100(100 by default)
|
33
33
|
format(String) - if you need a certain format of images(jpg, png, etc.)
|
34
34
|
formats(Array) - array of allow formats
|
35
35
|
```
|
data/image_searcher.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'image_searcher/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "image_searcher"
|
8
|
-
spec.version = '0.1.
|
8
|
+
spec.version = '0.1.5'
|
9
9
|
spec.authors = ["Vitaliy"]
|
10
10
|
spec.email = ["vitaliy.fry@gmail.com"]
|
11
11
|
|
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.12"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rspec"
|
33
|
-
spec.add_dependency "httparty"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
33
|
+
spec.add_dependency "httparty", "~> 0.14.0"
|
34
34
|
end
|
data/lib/image_searcher.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module ImageSearcher
|
2
|
+
class Client
|
3
|
+
attr_reader :options, :result
|
4
|
+
|
5
|
+
def search(opts = {})
|
6
|
+
@options = opts
|
7
|
+
raise_errors
|
8
|
+
@result = ImageSearcher::API.get_json(build_json_url)
|
9
|
+
filter_by_format if options[:format]
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def raise_errors
|
17
|
+
raise "Missing params" if options[:query].nil?
|
18
|
+
raise "Missing query" if options[:query].empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_json_url
|
22
|
+
base_uri = ImageSearcher::API::BASE_URI
|
23
|
+
url = "#{base_uri}?q=#{options[:query]}"
|
24
|
+
url += "&count=#{options[:count]}" if options[:count]
|
25
|
+
url
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_by_format
|
29
|
+
format = options[:format]
|
30
|
+
if format.is_a?(Array)
|
31
|
+
format.each do |f|
|
32
|
+
@result = result.keep_if { |h| h['url'].match(/.#{f}/i) }
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@result = result.keep_if { |h| h["url"].match(/.#{format}/i) }
|
36
|
+
end
|
37
|
+
|
38
|
+
@result
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaliy
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.5.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: httparty
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.14.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.14.0
|
69
69
|
description: A ruby wrapper for the Ababeen images search API
|
70
70
|
email:
|
71
71
|
- vitaliy.fry@gmail.com
|
@@ -85,8 +85,7 @@ files:
|
|
85
85
|
- image_searcher.gemspec
|
86
86
|
- lib/image_searcher.rb
|
87
87
|
- lib/image_searcher/api.rb
|
88
|
-
- lib/image_searcher/
|
89
|
-
- lib/image_searcher/search.rb
|
88
|
+
- lib/image_searcher/client.rb
|
90
89
|
- lib/image_searcher/version.rb
|
91
90
|
homepage: https://github.com/Frylock13/image_searcher
|
92
91
|
licenses:
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ImageSearcher::Filter
|
2
|
-
|
3
|
-
def filter_by_format(result, format)
|
4
|
-
result.keep_if { |h| h["url"].match(/.#{format}/i) }
|
5
|
-
end
|
6
|
-
|
7
|
-
def filter_by_formats(result, formats)
|
8
|
-
formats.each do |f|
|
9
|
-
result = result.keep_if { |h| h['url'].match(/.#{f}/i) }
|
10
|
-
end
|
11
|
-
|
12
|
-
result
|
13
|
-
end
|
14
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module ImageSearcher
|
2
|
-
|
3
|
-
require_relative 'filter'
|
4
|
-
extend Filter
|
5
|
-
|
6
|
-
def self.search(options = {})
|
7
|
-
raise_errors(options)
|
8
|
-
url = build_json_url(options)
|
9
|
-
result = ImageSearcher::API.get_json(url)
|
10
|
-
perform_filter_params(result, options)
|
11
|
-
result
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.raise_errors(options)
|
15
|
-
raise "Missing params" if options[:query].nil?
|
16
|
-
raise "Missing query" if options[:query].empty?
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.build_json_url(options)
|
20
|
-
base_uri = ImageSearcher::API::BASE_URI
|
21
|
-
url = "#{base_uri}?q=#{options[:query]}"
|
22
|
-
url += "&count=#{options[:count]}" if options[:count]
|
23
|
-
url
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.perform_filter_params(result, options)
|
27
|
-
if options[:format]
|
28
|
-
result = filter_by_format(result, options[:format])
|
29
|
-
end
|
30
|
-
|
31
|
-
if options[:formats]
|
32
|
-
result = filter_by_formats(result, options[:formats])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|