rack-middleware-google-image 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,5 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # Rack::Middleware::Google::Image
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/banyan/rack-middleware-google-image.png)](http://travis-ci.org/banyan/rack-middleware-google-image)
3
4
  ![image](http://i.imgur.com/LEnwb.png?1)
4
5
 
5
6
  rack middleware to response any image file via google search
6
7
 
8
+ the original idea comes from [here](http://kimoto.hatenablog.com/entry/2012/05/06/113043)
9
+
7
10
  ## Installation
8
11
 
9
12
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $:.unshift(File.dirname(__FILE__))
5
+
6
+ require 'hello_world'
7
+ require 'rack-middleware-google-image'
8
+
9
+ use Rack::GoogleImage
10
+ run HelloWorld.new
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ class HelloWorld
4
+ def call(env)
5
+ [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
6
+ end
7
+ end
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  require 'google_image_api'
2
4
  require 'open-uri'
3
5
 
@@ -2,7 +2,7 @@ module Rack
2
2
  module Middleware
3
3
  module Google
4
4
  module Image
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
8
8
  end
@@ -15,5 +15,10 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Rack::Middleware::Google::Image::VERSION
17
17
 
18
- gem.add_runtime_dependency "google_image_api"
18
+ gem.add_runtime_dependency "google_image_api"
19
+
20
+ gem.add_development_dependency "rspec", "~> 2.10.0"
21
+ gem.add_development_dependency 'rake', '>= 0.9.2.2'
22
+ gem.add_development_dependency "rack", '>= 1.3.5'
23
+ gem.add_development_dependency 'rack-test', '>= 0.5.3'
19
24
  end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'Rack::GoogleImage' do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ Rack::GoogleImage.new(TestRackApp.new)
8
+ end
9
+
10
+ describe '#call' do
11
+
12
+ context "GET /" do
13
+ before(:each) do
14
+ get '/'
15
+ end
16
+
17
+ it "should return status code 200" do
18
+ last_response.status.should == 200
19
+ end
20
+
21
+ it "should return html" do
22
+ last_response.body.should == TestRackApp::DummyBody.to_s
23
+ end
24
+ end
25
+
26
+ context "GET /yahoo.jpg" do
27
+ before(:each) do
28
+ Rack::GoogleImage.any_instance.stub(:search_image).and_return('foo')
29
+ get '/yahoo.jpg'
30
+ end
31
+
32
+ it "should return jpg via google search" do
33
+ last_response.body.should == "foo"
34
+ end
35
+
36
+ it "should change jpg content" do
37
+ last_response.body.should_not == TestRackApp::DummyImage.to_s
38
+ end
39
+
40
+ it "should return status code 200" do
41
+ last_response.status.should == 200
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ %w(rack rack/test rack-middleware-google-image rspec).each {|f| require f}
5
+
6
+ class TestRackApp
7
+ DummyBody = <<-HTML
8
+ <html>
9
+ <head></head>
10
+ <body>
11
+ <p>Dummy Rack!</p>
12
+ </body>
13
+ </html>
14
+ HTML
15
+
16
+ DummyImage = <<-BIN
17
+ blablabla
18
+ BIN
19
+
20
+ def call(env)
21
+ case env['PATH_INFO']
22
+ when '/'
23
+ [200, {"Content-Type" => "text/html"}, [DummyBody]]
24
+ when /.*\.jpg/
25
+ [200, {"Content-Type" => "image/ipg"}, [DummyImage]]
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-middleware-google-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-09 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google_image_api
16
- requirement: &70180781254280 !ruby/object:Gem::Requirement
16
+ requirement: &70336549095040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,51 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70180781254280
24
+ version_requirements: *70336549095040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70336549105200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.10.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70336549105200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70336549099800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70336549099800
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack
49
+ requirement: &70336549107280 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70336549107280
58
+ - !ruby/object:Gem::Dependency
59
+ name: rack-test
60
+ requirement: &70336549120580 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 0.5.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70336549120580
25
69
  description: rack middleware to response any image file via google search
26
70
  email:
27
71
  - ameutau@gmail.com
@@ -30,13 +74,19 @@ extensions: []
30
74
  extra_rdoc_files: []
31
75
  files:
32
76
  - .gitignore
77
+ - .rspec
78
+ - .travis.yml
33
79
  - Gemfile
34
80
  - LICENSE
35
81
  - README.md
36
82
  - Rakefile
83
+ - example/config.ru
84
+ - example/hello_world.rb
37
85
  - lib/rack-middleware-google-image.rb
38
86
  - lib/rack-middleware-google-image/version.rb
39
87
  - rack-middleware-google-image.gemspec
88
+ - spec/middleware_spec.rb
89
+ - spec/spec_helper.rb
40
90
  homepage: http://github.com/banyan/rack-middleware-google-image
41
91
  licenses: []
42
92
  post_install_message:
@@ -61,5 +111,7 @@ rubygems_version: 1.8.11
61
111
  signing_key:
62
112
  specification_version: 3
63
113
  summary: rack middleware to response any image file via google search
64
- test_files: []
114
+ test_files:
115
+ - spec/middleware_spec.rb
116
+ - spec/spec_helper.rb
65
117
  has_rdoc: