image_searcher 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/README.md +11 -4
- data/image_searcher.gemspec +1 -1
- data/lib/image_searcher.rb +1 -3
- data/lib/image_searcher/filter.rb +14 -0
- data/lib/image_searcher/search.rb +26 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 093042c5007de3e38b446c9411769f78d17e3674
|
4
|
+
data.tar.gz: e8a24e871ec2a4a54ab6ab305cfb312f3f95d781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4da65fa188fac36cc448e187d47f19ea64c57766b24042850ae64b9a51b7e5db0378bf301d3de2c806da0d636c87ab51545c951ddeea8c67f3a25f7ea5eb4f2
|
7
|
+
data.tar.gz: 9565e7c7fc49bba02f81a7be70f1522d4aec3bfcf00ae5775055486095cc1ba0c1f4e233081f0b22abe6719bd62ebae50191f80cf2632a9d4e151c44e38e525e
|
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A ruby wrapper for the [Ababeen](http://api.ababeen.com) Image Search API v1.0 -
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'image_searcher', '~> 0.1.
|
10
|
+
gem 'image_searcher', '~> 0.1.4'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -24,16 +24,23 @@ Or install it yourself as:
|
|
24
24
|
images = ImageSearcher.search(query: "New York")
|
25
25
|
```
|
26
26
|
|
27
|
-
And you've got an array of objects. By default the result has `
|
27
|
+
And you've got an array of objects. By default the result has `100` nested arrays.
|
28
28
|
|
29
29
|
**Available options**:
|
30
30
|
```
|
31
31
|
query(String)
|
32
32
|
count(Integer) - maximum 100(10 by default)
|
33
|
+
format(String) - if you need a certain format of images(jpg, png, etc.)
|
34
|
+
formats(Array) - array of allow formats
|
33
35
|
```
|
34
|
-
|
36
|
+
Examples:
|
35
37
|
|
36
|
-
|
38
|
+
`ImageSearcher.search(query: 'New York', count: 66)`
|
39
|
+
`ImageSearcher.search(query: 'New York', format: 'jpg')`
|
40
|
+
`ImageSearcher.search(query: 'New York', formats: ['jpg', 'png'])`
|
41
|
+
|
42
|
+
Also you can see a nice preview of a result:
|
43
|
+
http://api.ababeen.com/api/images.php?q=New%York&preview=true&count=100
|
37
44
|
|
38
45
|
## Contributing
|
39
46
|
|
data/image_searcher.gemspec
CHANGED
data/lib/image_searcher.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
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,11 +1,35 @@
|
|
1
1
|
module ImageSearcher
|
2
|
+
|
3
|
+
require_relative 'filter'
|
4
|
+
extend Filter
|
5
|
+
|
2
6
|
def self.search(options = {})
|
3
|
-
|
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
|
4
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)
|
5
20
|
base_uri = ImageSearcher::API::BASE_URI
|
6
21
|
url = "#{base_uri}?q=#{options[:query]}"
|
7
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
|
8
30
|
|
9
|
-
|
31
|
+
if options[:formats]
|
32
|
+
result = filter_by_formats(result, options[:formats])
|
33
|
+
end
|
10
34
|
end
|
11
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaliy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".DS_Store"
|
76
77
|
- ".gitignore"
|
77
78
|
- CODE_OF_CONDUCT.md
|
78
79
|
- Gemfile
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- image_searcher.gemspec
|
85
86
|
- lib/image_searcher.rb
|
86
87
|
- lib/image_searcher/api.rb
|
88
|
+
- lib/image_searcher/filter.rb
|
87
89
|
- lib/image_searcher/search.rb
|
88
90
|
- lib/image_searcher/version.rb
|
89
91
|
homepage: https://github.com/Frylock13/image_searcher
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.5.1
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: A ruby wrapper for the Ababeen images search API
|