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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 093042c5007de3e38b446c9411769f78d17e3674
4
- data.tar.gz: e8a24e871ec2a4a54ab6ab305cfb312f3f95d781
3
+ metadata.gz: b0fbd835cba4e16b93ff11774c9fc7070bd7fe94
4
+ data.tar.gz: 13ac2936185dd3407597a4b6f69338cc5e874c5c
5
5
  SHA512:
6
- metadata.gz: c4da65fa188fac36cc448e187d47f19ea64c57766b24042850ae64b9a51b7e5db0378bf301d3de2c806da0d636c87ab51545c951ddeea8c67f3a25f7ea5eb4f2
7
- data.tar.gz: 9565e7c7fc49bba02f81a7be70f1522d4aec3bfcf00ae5775055486095cc1ba0c1f4e233081f0b22abe6719bd62ebae50191f80cf2632a9d4e151c44e38e525e
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(10 by default)
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
  ```
@@ -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.4'
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
@@ -1,6 +1,6 @@
1
1
  require 'image_searcher/version'
2
2
  require 'httparty'
3
3
  require 'image_searcher/api'
4
- require 'image_searcher/search'
4
+ require 'image_searcher/client'
5
5
 
6
6
  module ImageSearcher; end
@@ -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
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: '0'
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: '0'
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: '0'
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: '0'
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/filter.rb
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