image_suckr 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc2f4fc1f6b97bb5b6f48343beb07d432c5bc310
4
+ data.tar.gz: 219c2a22cd8dc9fd529baea4df9e3592330571c1
5
+ SHA512:
6
+ metadata.gz: 01cf6fe286ee58c4be1da94609cab58338a721556ee0e967c6c0dc78db3e45d96364b564cca58e8269d6352275e735f5d6722e10c07082c46c9c9275b670bcdd
7
+ data.tar.gz: fe3db210a90aaa8f54562d67fb8f340a7c255ca5b98bb498c8787c1d7c6c04a14f22cedafd6a5cddfc6261ae4f2d900438f96fa8de5ebe3bc39daa2422eb6b43
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
+ .ruby-version
7
+ .ruby-gemset
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Description
2
2
  ---
3
- ImageSuckr is a ruby gem that allows you to get random images from the web for seeding and testing purposes.
3
+ ImageSuckr is a ruby gem that allows you to get random images from the web for seeding and testing purposes.
4
4
 
5
5
  By now, only Google is supported as images source.
6
6
 
@@ -8,23 +8,23 @@ Installation
8
8
  ---
9
9
  1. Add `gem 'image_suckr'` to your Gemfile
10
10
  2. Run `bundle install`
11
-
11
+
12
12
  Basic use
13
13
  ---
14
14
  **Create an ImageSuckr object:**
15
-
16
- suckr = ImageSuckr::GoogleSuckr.new
15
+
16
+ suckr = ImageSuckr::GoogleSuckr.new
17
17
 
18
18
  **To get a fully random image URL:**
19
-
19
+
20
20
  suckr.get_image_url
21
-
21
+
22
22
  **To get a random image URL based on a query:**
23
23
 
24
24
  suckr.get_image_url({"q" => "car"})
25
25
 
26
26
  _All [Google Image Search API arguments](http://code.google.com/apis/imagesearch/v1/jsondevguide.html#json_args) are supported and you can use them to filter your results._
27
-
27
+
28
28
  **To get the image content instead of the URL:**
29
29
 
30
30
  suckr.get_image_content
@@ -32,10 +32,10 @@ _All [Google Image Search API arguments](http://code.google.com/apis/imagesearch
32
32
  **To get a file reference to the image:**
33
33
 
34
34
  suckr.get_image_file
35
-
35
+
36
36
  Other useful examples
37
37
  ---
38
-
38
+
39
39
  **To get a [RMagick](http://rmagick.rubyforge.org/) image:**
40
40
 
41
41
  image = Magick::Image.from_blob(suckr.get_image_content).first
@@ -43,11 +43,15 @@ Other useful examples
43
43
  **To get a [MiniMagick](https://github.com/probablycorey/mini_magick) image:**
44
44
 
45
45
  image = MiniMagick::Image.read(suckr.get_image_content)
46
-
46
+
47
47
  or
48
-
48
+
49
49
  image = MiniMagick::Image.open(suckr.get_image_url)
50
-
50
+
51
51
  **To use with [Paperclip](https://github.com/thoughtbot/paperclip):**
52
52
 
53
- car.picture = suckr.get_image_file({"q" => "car"})
53
+ car.picture = suckr.get_image_file({"q" => "car"})
54
+
55
+ **To use with [Carrierwave](https://github.com/carrierwaveuploader/carrierwave):**
56
+
57
+ car.remote_picture_url = suckr.get_image_url({"q" => "car"})
@@ -1,22 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "image_suckr/version"
3
+ require 'image_suckr/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "image_suckr"
6
+ s.name = 'image_suckr'
7
7
  s.version = ImageSuckr::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Mauricio Miranda"]
10
- s.email = ["maurimiranda@gmail.com"]
11
- s.homepage = "https://github.com/maurimiranda/image_suckr"
9
+ s.author = 'Mauricio Miranda'
10
+ s.email = 'maurimiranda@gmail.com'
11
+ s.homepage = 'https://github.com/maurimiranda/image_suckr'
12
12
  s.summary = %q{Gets images randomly from the web}
13
13
  s.description = %q{ImageSuckr is a ruby gem that allows you to get random images from Google for seeding purposes.}
14
+ s.license = 'GPL-3.0'
14
15
 
15
16
  s.rubyforge_project = "image_suckr"
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
- s.add_development_dependency 'rspec'
21
+ s.require_paths = ['lib']
22
+ s.add_development_dependency 'rspec', '~> 3'
22
23
  end
@@ -1,5 +1,5 @@
1
1
  module ImageSuckr
2
-
2
+
3
3
  class GoogleSuckr
4
4
  attr_accessor :default_params
5
5
 
@@ -24,16 +24,20 @@ module ImageSuckr
24
24
 
25
25
  resp = Net::HTTP.get_response(URI.parse(url))
26
26
  result = JSON.parse(resp.body)
27
+ return nil if result.nil?
28
+
27
29
  response_data = result["responseData"]
30
+ return nil if response_data.nil?
28
31
 
29
32
  result_size = response_data["results"].count
33
+ return nil unless result_size > 0
30
34
  result["responseData"]["results"][rand(result_size)]["url"]
31
35
  end
32
36
 
33
37
  def get_image_content(params = {})
34
38
  Net::HTTP.get_response(URI.parse(get_image_url(params))).body
35
39
  end
36
-
40
+
37
41
  def get_image_file(params = {})
38
42
  open(URI.parse(get_image_url(params)))
39
43
  end
@@ -1,3 +1,3 @@
1
1
  module ImageSuckr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,43 +5,43 @@ describe "ImageSuckr" do
5
5
  it "should have set the default parameters" do
6
6
  image = ImageSuckr::GoogleSuckr.new
7
7
 
8
- image.default_params.should_not be_nil
8
+ expect(image.default_params).to be_truthy
9
9
  end
10
10
 
11
11
  it "should have default values" do
12
12
  image = ImageSuckr::GoogleSuckr.new
13
13
 
14
- image.default_params[:rsz].should be_eql("8")
15
- image.default_params[:v].should be_eql("1.0")
14
+ expect(image.default_params[:rsz]).to be_eql("8")
15
+ expect(image.default_params[:v]).to be_eql("1.0")
16
16
  end
17
17
 
18
18
  it "should provide access to override default params" do
19
19
  params = {:rsz => "6", :v => "1.1", :as_filetype => "png"}
20
20
  image = ImageSuckr::GoogleSuckr.new
21
-
22
- image.default_params[:rsz].should be_eql "8"
21
+
22
+ expect(image.default_params[:rsz]).to be_eql "8"
23
23
  image.default_params = params
24
- image.default_params[:rsz].should be_eql "6"
24
+ expect(image.default_params[:rsz]).to be_eql "6"
25
25
  end
26
26
 
27
27
  it "should override the default values" do
28
28
  params = {:rsz => "6", :v => "1.1", :as_filetype => "png"}
29
29
  image = ImageSuckr::GoogleSuckr.new(params)
30
-
31
- image.default_params[:v].should be_eql params[:v]
32
- image.default_params[:rsz].should be_eql params[:rsz]
30
+
31
+ expect(image.default_params[:v]).to be_eql params[:v]
32
+ expect(image.default_params[:rsz]).to be_eql params[:rsz]
33
33
  end
34
34
 
35
- it "should return a valid URL" do
35
+ it "should return a valid URL or nil" do
36
36
  image = ImageSuckr::GoogleSuckr.new
37
- open(URI.parse(image.get_image_url)).should be_a Tempfile
37
+ expect(open(URI.parse(image.get_image_url))).to be_a(Tempfile).or be_nil
38
38
  end
39
39
 
40
- it "should return a temp file object" do
40
+ it "should return a temp file object or nil" do
41
41
  image = ImageSuckr::GoogleSuckr.new
42
42
  file = image.get_image_file
43
43
 
44
- file.should be_a Tempfile
44
+ expect(file).to be_a(Tempfile).or be_nil
45
45
  end
46
46
 
47
47
  end
metadata CHANGED
@@ -1,42 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_suckr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mauricio Miranda
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: '3'
30
27
  description: ImageSuckr is a ruby gem that allows you to get random images from Google
31
28
  for seeding purposes.
32
- email:
33
- - maurimiranda@gmail.com
29
+ email: maurimiranda@gmail.com
34
30
  executables: []
35
31
  extensions: []
36
32
  extra_rdoc_files: []
37
33
  files:
38
- - .gitignore
39
- - .rspec
34
+ - ".gitignore"
35
+ - ".rspec"
40
36
  - Gemfile
41
37
  - README.md
42
38
  - Rakefile
@@ -47,28 +43,28 @@ files:
47
43
  - lib/support.rb
48
44
  - spec/google_suckr_spec.rb
49
45
  homepage: https://github.com/maurimiranda/image_suckr
50
- licenses: []
46
+ licenses:
47
+ - GPL-3.0
48
+ metadata: {}
51
49
  post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
- - - ! '>='
55
+ - - ">="
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
- - - ! '>='
60
+ - - ">="
65
61
  - !ruby/object:Gem::Version
66
62
  version: '0'
67
63
  requirements: []
68
64
  rubyforge_project: image_suckr
69
- rubygems_version: 1.8.24
65
+ rubygems_version: 2.2.2
70
66
  signing_key:
71
- specification_version: 3
67
+ specification_version: 4
72
68
  summary: Gets images randomly from the web
73
69
  test_files:
74
70
  - spec/google_suckr_spec.rb