httpthumbnailer-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/features/step_definitions/httpthumbnailer-client_steps.rb +0 -0
- data/features/support/env.rb +13 -0
- data/httpthumbnailer-client.gemspec +80 -0
- data/lib/httpthumbnailer-client/multipart_response.rb +45 -0
- data/lib/httpthumbnailer-client.rb +57 -0
- data/spec/httpthumbnailer-client_spec.rb +47 -0
- data/spec/multipart_response_spec.rb +95 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/test.jpg +0 -0
- metadata +218 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "httpclient", ">= 2.2.1"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "rspec", "~> 2.3.0"
|
9
|
+
gem "cucumber", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem "rdoc", "~> 3.9"
|
14
|
+
gem "daemon", "~> 1"
|
15
|
+
gem "httpthumbnailer", "~> 0.0.1"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
builder (3.0.0)
|
5
|
+
cgi_multipart_eof_fix (2.5.0)
|
6
|
+
cucumber (1.1.3)
|
7
|
+
builder (>= 2.1.2)
|
8
|
+
diff-lcs (>= 1.1.2)
|
9
|
+
gherkin (~> 2.6.7)
|
10
|
+
json (>= 1.4.6)
|
11
|
+
term-ansicolor (>= 1.0.6)
|
12
|
+
daemon (1.1.0)
|
13
|
+
daemons (1.1.4)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
fastthread (1.0.7)
|
16
|
+
gem_plugin (0.2.3)
|
17
|
+
gherkin (2.6.7)
|
18
|
+
json (>= 1.4.6)
|
19
|
+
git (1.2.5)
|
20
|
+
haml (3.1.3)
|
21
|
+
httpclient (2.2.3)
|
22
|
+
httpthumbnailer (0.0.1)
|
23
|
+
haml (~> 3)
|
24
|
+
mongrel (>= 1.1.5)
|
25
|
+
rmagick (~> 2)
|
26
|
+
sinatra (>= 1.2.6)
|
27
|
+
jeweler (1.6.4)
|
28
|
+
bundler (~> 1.0)
|
29
|
+
git (>= 1.2.5)
|
30
|
+
rake
|
31
|
+
json (1.6.1)
|
32
|
+
mongrel (1.1.5)
|
33
|
+
cgi_multipart_eof_fix (>= 2.4)
|
34
|
+
daemons (>= 1.0.3)
|
35
|
+
fastthread (>= 1.0.1)
|
36
|
+
gem_plugin (>= 0.2.3)
|
37
|
+
rack (1.3.5)
|
38
|
+
rack-protection (1.1.4)
|
39
|
+
rack
|
40
|
+
rake (0.9.2.2)
|
41
|
+
rcov (0.9.11)
|
42
|
+
rdoc (3.9.4)
|
43
|
+
rmagick (2.13.1)
|
44
|
+
rspec (2.3.0)
|
45
|
+
rspec-core (~> 2.3.0)
|
46
|
+
rspec-expectations (~> 2.3.0)
|
47
|
+
rspec-mocks (~> 2.3.0)
|
48
|
+
rspec-core (2.3.1)
|
49
|
+
rspec-expectations (2.3.0)
|
50
|
+
diff-lcs (~> 1.1.2)
|
51
|
+
rspec-mocks (2.3.0)
|
52
|
+
sinatra (1.3.1)
|
53
|
+
rack (~> 1.3, >= 1.3.4)
|
54
|
+
rack-protection (~> 1.1, >= 1.1.2)
|
55
|
+
tilt (~> 1.3, >= 1.3.3)
|
56
|
+
term-ansicolor (1.0.7)
|
57
|
+
tilt (1.3.3)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
bundler (~> 1.0.0)
|
64
|
+
cucumber
|
65
|
+
daemon (~> 1)
|
66
|
+
httpclient (>= 2.2.1)
|
67
|
+
httpthumbnailer (~> 0.0.1)
|
68
|
+
jeweler (~> 1.6.4)
|
69
|
+
rcov
|
70
|
+
rdoc (~> 3.9)
|
71
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jakub Pastuszek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= httpthumbnailer-client
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to httpthumbnailer-client
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Jakub Pastuszek. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "httpthumbnailer-client"
|
18
|
+
gem.homepage = "http://github.com/jpastuszek/httpthumbnailer-client"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{API client for httpthumbniler server}
|
21
|
+
gem.description = %Q{Thumbnails images using httpthumbniler server}
|
22
|
+
gem.email = "jpastuszek@gmail.com"
|
23
|
+
gem.authors = ["Jakub Pastuszek"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'cucumber/rake/task'
|
40
|
+
Cucumber::Rake::Task.new(:features)
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
RDoc::Task.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "httpthumbnailer-client #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
11
|
+
require 'httpthumbnailer-client'
|
12
|
+
|
13
|
+
require 'rspec/expectations'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "httpthumbnailer-client"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jakub Pastuszek"]
|
12
|
+
s.date = "2011-11-23"
|
13
|
+
s.description = "Thumbnails images using httpthumbniler server"
|
14
|
+
s.email = "jpastuszek@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"features/step_definitions/httpthumbnailer-client_steps.rb",
|
29
|
+
"features/support/env.rb",
|
30
|
+
"httpthumbnailer-client.gemspec",
|
31
|
+
"lib/httpthumbnailer-client.rb",
|
32
|
+
"lib/httpthumbnailer-client/multipart_response.rb",
|
33
|
+
"spec/httpthumbnailer-client_spec.rb",
|
34
|
+
"spec/multipart_response_spec.rb",
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/test.jpg"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/jpastuszek/httpthumbnailer-client"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.10"
|
42
|
+
s.summary = "API client for httpthumbniler server"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<httpclient>, [">= 2.2.1"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
50
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
|
55
|
+
s.add_development_dependency(%q<daemon>, ["~> 1"])
|
56
|
+
s.add_development_dependency(%q<httpthumbnailer>, ["~> 0.0.1"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<httpclient>, [">= 2.2.1"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
60
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9"])
|
65
|
+
s.add_dependency(%q<daemon>, ["~> 1"])
|
66
|
+
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.1"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<httpclient>, [">= 2.2.1"])
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
71
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9"])
|
76
|
+
s.add_dependency(%q<daemon>, ["~> 1"])
|
77
|
+
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.1"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class MultipartResponse
|
2
|
+
class NoBoundaryFoundInContentTypeError < ArgumentError
|
3
|
+
def initialize(content_type_header, exception)
|
4
|
+
super("Content-Type header of '#{content_type_header}' has no boundary defined: #{exception.class.name}: #{exception}")
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Part
|
9
|
+
def initialize(data)
|
10
|
+
if data.include?("\r\n\r\n")
|
11
|
+
headers, *body = *data.split("\r\n\r\n")
|
12
|
+
@headers = Hash[headers.split("\r\n").map{|h| h.split(/: ?/)}]
|
13
|
+
@body = body.join("\r\n\r\n")
|
14
|
+
else
|
15
|
+
@headers = {'Content-Type' => 'text/plain'}
|
16
|
+
@body = data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :headers, :body
|
21
|
+
alias :header :headers
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(content_type_header, body)
|
25
|
+
@boundary = begin
|
26
|
+
content_type_header.split(';').map{|e| e.strip}.select{|e| e =~ /^boundary=/}.first.match(/^boundary="(.*)"/)[1]
|
27
|
+
rescue => e
|
28
|
+
raise NoBoundaryFoundInContentTypeError.new(content_type_header, e)
|
29
|
+
end
|
30
|
+
|
31
|
+
body, epilogue = *body.split("--#{@boundary}--")
|
32
|
+
preamble, *parts = *body.split("--#{@boundary}")
|
33
|
+
|
34
|
+
@preamble = preamble.sub(/\r\n$/m, '')
|
35
|
+
@preamble = nil if @preamble.empty?
|
36
|
+
|
37
|
+
@epilogue = epilogue.sub(/^\r\n/m, '') if epilogue
|
38
|
+
|
39
|
+
@parts = parts.map{|p| p.sub(/^\r\n/m, '').sub(/\r\n$/m, '')}.map{|p| Part.new(p)}
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :boundary, :preamble, :parts, :epilogue
|
43
|
+
alias :part :parts
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'httpclient'
|
3
|
+
require 'httpthumbnailer-client/multipart_response'
|
4
|
+
|
5
|
+
class HTTPThumbnailerClient
|
6
|
+
class URIBuilder
|
7
|
+
def initialize(service_uri, &block)
|
8
|
+
@specs = []
|
9
|
+
@service_uri = service_uri
|
10
|
+
instance_eval &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def get
|
14
|
+
"#{@service_uri}/#{@specs.join('/')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.thumbnail(&block)
|
18
|
+
self.new('/thumbnail', &block).get
|
19
|
+
end
|
20
|
+
|
21
|
+
def thumbnail(method, width, height, format = 'JPEG', options = {})
|
22
|
+
args = []
|
23
|
+
args << method.to_s
|
24
|
+
args << width.to_s
|
25
|
+
args << height.to_s
|
26
|
+
args << format.to_s
|
27
|
+
|
28
|
+
options.keys.sort{|a, b| a.to_s <=> b.to_s}.each do |key|
|
29
|
+
args << "#{key}:#{options[key]}"
|
30
|
+
end
|
31
|
+
|
32
|
+
@specs << args.join(',')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Thumbnail
|
37
|
+
def initialize(mime_type, data)
|
38
|
+
@mime_type = mime_type
|
39
|
+
@data = data
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :mime_type, :data
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(server_url)
|
46
|
+
@server_url = server_url
|
47
|
+
end
|
48
|
+
|
49
|
+
def thumbnail(data, &block)
|
50
|
+
uri = URIBuilder.thumbnail(&block)
|
51
|
+
res = HTTPClient.new.request('PUT', "#{@server_url}#{uri}", nil, data)
|
52
|
+
MultipartResponse.new(res.header['Content-Type'].last, res.body).parts.map do |part|
|
53
|
+
Thumbnail.new(part.header['Content-Type'], part.body)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'httpthumbnailer-client'
|
4
|
+
|
5
|
+
describe HTTPThumbnailerClient::URIBuilder do
|
6
|
+
it "should allow building request for thumbnail set" do
|
7
|
+
HTTPThumbnailerClient::URIBuilder.thumbnail do
|
8
|
+
thumbnail 'crop', 16, 16, 'JPEG'
|
9
|
+
thumbnail 'pad', 32, 64, 'PNG', :magick => 'xdfa', :number => 2
|
10
|
+
end.should == '/thumbnail/crop,16,16,JPEG/pad,32,64,PNG,magick:xdfa,number:2'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe HTTPThumbnailerClient do
|
15
|
+
before :all do
|
16
|
+
server_start
|
17
|
+
@data = File.read(spec_dir + 'test.jpg')
|
18
|
+
end
|
19
|
+
|
20
|
+
after :all do
|
21
|
+
server_stop
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return set of thumbnails matching specified specification" do
|
25
|
+
thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail(@data) do
|
26
|
+
thumbnail 'crop', 6, 3, 'JPEG'
|
27
|
+
thumbnail 'crop', 8, 8, 'PNG'
|
28
|
+
thumbnail 'crop', 4, 4, 'PNG'
|
29
|
+
end
|
30
|
+
|
31
|
+
thumbs[0].mime_type.should == 'image/jpeg'
|
32
|
+
t, s = identify(thumbs[0].data)
|
33
|
+
t.should == 'JPEG'
|
34
|
+
s.should == '6x3'
|
35
|
+
|
36
|
+
thumbs[1].mime_type.should == 'image/png'
|
37
|
+
t, s = identify(thumbs[1].data)
|
38
|
+
t.should == 'PNG'
|
39
|
+
s.should == '8x8'
|
40
|
+
|
41
|
+
thumbs[2].mime_type.should == 'image/png'
|
42
|
+
t, s = identify(thumbs[2].data)
|
43
|
+
t.should == 'PNG'
|
44
|
+
s.should == '4x4'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'httpthumbnailer-client/multipart_response'
|
3
|
+
|
4
|
+
describe MultipartResponse do
|
5
|
+
describe "parsing" do
|
6
|
+
it "should privide preamble, parts with headers and epilogue" do
|
7
|
+
content_type_header = 'multipart/mixed; boundary="cut here"'
|
8
|
+
body =
|
9
|
+
"""hello
|
10
|
+
--cut here
|
11
|
+
Content-Type: text/plain
|
12
|
+
|
13
|
+
part 1
|
14
|
+
--cut here
|
15
|
+
Content-Type: text/html
|
16
|
+
Content-Transfer-Encoding: base64
|
17
|
+
|
18
|
+
part 2
|
19
|
+
--cut here
|
20
|
+
part 3
|
21
|
+
--cut here--
|
22
|
+
world""".gsub!("\n", "\r\n")
|
23
|
+
|
24
|
+
mr = MultipartResponse.new(content_type_header, body)
|
25
|
+
mr.preamble.should == "hello"
|
26
|
+
|
27
|
+
mr.parts[0].body.should == "part 1"
|
28
|
+
mr.parts[0].header['Content-Type'].should == "text/plain"
|
29
|
+
|
30
|
+
mr.parts[1].body.should == "part 2"
|
31
|
+
mr.parts[1].header['Content-Type'].should == "text/html"
|
32
|
+
mr.parts[1].header['Content-Transfer-Encoding'].should == "base64"
|
33
|
+
|
34
|
+
mr.parts[2].body.should == "part 3"
|
35
|
+
|
36
|
+
mr.epilogue.should == "world"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should privide nil preamble if no prologue sent" do
|
40
|
+
content_type_header = 'multipart/mixed; boundary="cut here"'
|
41
|
+
body =
|
42
|
+
"""--cut here
|
43
|
+
part 1
|
44
|
+
--cut here--""".gsub!("\n", "\r\n")
|
45
|
+
|
46
|
+
mr = MultipartResponse.new(content_type_header, body)
|
47
|
+
mr.preamble.should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should privide nil epilogue if no epilogue sent" do
|
51
|
+
content_type_header = 'multipart/mixed; boundary="cut here"'
|
52
|
+
body =
|
53
|
+
"""--cut here
|
54
|
+
part 1
|
55
|
+
--cut here--""".gsub!("\n", "\r\n")
|
56
|
+
|
57
|
+
mr = MultipartResponse.new(content_type_header, body)
|
58
|
+
mr.epilogue.should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should provide default mime type of text/plain if no Content-Type header specified" do
|
62
|
+
content_type_header = 'multipart/mixed; boundary="cut here"'
|
63
|
+
body =
|
64
|
+
"""--cut here
|
65
|
+
part 1
|
66
|
+
--cut here--""".gsub!("\n", "\r\n")
|
67
|
+
|
68
|
+
mr = MultipartResponse.new(content_type_header, body)
|
69
|
+
mr.part[0].header['Content-Type'].should == 'text/plain'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should fail with MultipartResponse::NoBoundaryFoundInContentTypeError if no boundary specified in content type header" do
|
73
|
+
lambda {
|
74
|
+
MultipartResponse.new("fas", "")
|
75
|
+
}.should raise_error MultipartResponse::NoBoundaryFoundInContentTypeError
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "provides part alias" do
|
80
|
+
content_type_header = 'multipart/mixed; boundary="cut here"'
|
81
|
+
body =
|
82
|
+
"""--cut here
|
83
|
+
part 1
|
84
|
+
--cut here
|
85
|
+
part 2
|
86
|
+
--cut here
|
87
|
+
part 3
|
88
|
+
--cut here--""".gsub!("\n", "\r\n")
|
89
|
+
|
90
|
+
mr = MultipartResponse.new(content_type_header, body)
|
91
|
+
mr.part[0].body.should == "part 1"
|
92
|
+
mr.part[1].body.should == "part 2"
|
93
|
+
mr.part[2].body.should == "part 3"
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
# Requires supporting files with custom matchers and macros, etc,
|
6
|
+
# in ./support/ and its subdirectories.
|
7
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'daemon'
|
14
|
+
|
15
|
+
def gem_dir
|
16
|
+
Pathname.new(__FILE__).dirname + '..'
|
17
|
+
end
|
18
|
+
|
19
|
+
def spec_dir
|
20
|
+
gem_dir + 'spec'
|
21
|
+
end
|
22
|
+
|
23
|
+
def server_start
|
24
|
+
File.exist?("/tmp/httpthumbnailer.pid") and server_stop
|
25
|
+
fork do
|
26
|
+
Daemon.daemonize("/tmp/httpthumbnailer.pid", spec_dir + 'server.log')
|
27
|
+
exec("httpthumbnailer")
|
28
|
+
end
|
29
|
+
|
30
|
+
Timeout.timeout(10) do
|
31
|
+
begin
|
32
|
+
server_get '/'
|
33
|
+
rescue Errno::ECONNREFUSED
|
34
|
+
sleep 0.1
|
35
|
+
retry
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def server_stop
|
41
|
+
File.open("/tmp/httpthumbnailer.pid") do |pidf|
|
42
|
+
pid = pidf.read
|
43
|
+
|
44
|
+
Timeout.timeout(10) do
|
45
|
+
begin
|
46
|
+
loop do
|
47
|
+
ret = Process.kill("TERM", pid.strip.to_i)
|
48
|
+
sleep 0.1
|
49
|
+
end
|
50
|
+
rescue Errno::ESRCH
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def server_get(uri)
|
57
|
+
HTTPClient.new.get_content("http://localhost:3100#{uri}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def identify(data)
|
61
|
+
Open3.popen3('identify -') do |stdin, stdout, stderr|
|
62
|
+
stdin.write data
|
63
|
+
stdin.close
|
64
|
+
path, type, size, *rest = *stdout.read.split(' ')
|
65
|
+
return type, size
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/test.jpg
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: httpthumbnailer-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jakub Pastuszek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 5
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 2
|
31
|
+
- 1
|
32
|
+
version: 2.2.1
|
33
|
+
prerelease: false
|
34
|
+
name: httpclient
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
type: :development
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
version: 2.3.0
|
49
|
+
prerelease: false
|
50
|
+
name: rspec
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
type: :development
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
prerelease: false
|
64
|
+
name: cucumber
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
type: :development
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 23
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
- 0
|
77
|
+
- 0
|
78
|
+
version: 1.0.0
|
79
|
+
prerelease: false
|
80
|
+
name: bundler
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
type: :development
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 7
|
90
|
+
segments:
|
91
|
+
- 1
|
92
|
+
- 6
|
93
|
+
- 4
|
94
|
+
version: 1.6.4
|
95
|
+
prerelease: false
|
96
|
+
name: jeweler
|
97
|
+
version_requirements: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
type: :development
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
prerelease: false
|
110
|
+
name: rcov
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
type: :development
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ~>
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 21
|
120
|
+
segments:
|
121
|
+
- 3
|
122
|
+
- 9
|
123
|
+
version: "3.9"
|
124
|
+
prerelease: false
|
125
|
+
name: rdoc
|
126
|
+
version_requirements: *id007
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
type: :development
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 1
|
135
|
+
segments:
|
136
|
+
- 1
|
137
|
+
version: "1"
|
138
|
+
prerelease: false
|
139
|
+
name: daemon
|
140
|
+
version_requirements: *id008
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
type: :development
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ~>
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 29
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
- 0
|
152
|
+
- 1
|
153
|
+
version: 0.0.1
|
154
|
+
prerelease: false
|
155
|
+
name: httpthumbnailer
|
156
|
+
version_requirements: *id009
|
157
|
+
description: Thumbnails images using httpthumbniler server
|
158
|
+
email: jpastuszek@gmail.com
|
159
|
+
executables: []
|
160
|
+
|
161
|
+
extensions: []
|
162
|
+
|
163
|
+
extra_rdoc_files:
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.rdoc
|
166
|
+
files:
|
167
|
+
- .document
|
168
|
+
- .rspec
|
169
|
+
- Gemfile
|
170
|
+
- Gemfile.lock
|
171
|
+
- LICENSE.txt
|
172
|
+
- README.rdoc
|
173
|
+
- Rakefile
|
174
|
+
- VERSION
|
175
|
+
- features/step_definitions/httpthumbnailer-client_steps.rb
|
176
|
+
- features/support/env.rb
|
177
|
+
- httpthumbnailer-client.gemspec
|
178
|
+
- lib/httpthumbnailer-client.rb
|
179
|
+
- lib/httpthumbnailer-client/multipart_response.rb
|
180
|
+
- spec/httpthumbnailer-client_spec.rb
|
181
|
+
- spec/multipart_response_spec.rb
|
182
|
+
- spec/spec_helper.rb
|
183
|
+
- spec/test.jpg
|
184
|
+
homepage: http://github.com/jpastuszek/httpthumbnailer-client
|
185
|
+
licenses:
|
186
|
+
- MIT
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
hash: 3
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
version: "0"
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
hash: 3
|
207
|
+
segments:
|
208
|
+
- 0
|
209
|
+
version: "0"
|
210
|
+
requirements: []
|
211
|
+
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 1.8.10
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: API client for httpthumbniler server
|
217
|
+
test_files: []
|
218
|
+
|