httpthumbnailer-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/httpthumbnailer-client.gemspec +6 -5
- data/lib/httpthumbnailer-client.rb +7 -1
- data/spec/httpthumbnailer-client_spec.rb +36 -0
- data/spec/test-large.jpg +0 -0
- metadata +8 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
git (1.2.5)
|
20
20
|
haml (3.1.4)
|
21
21
|
httpclient (2.2.3)
|
22
|
-
httpthumbnailer (0.0.
|
22
|
+
httpthumbnailer (0.0.7)
|
23
23
|
haml (~> 3)
|
24
24
|
mongrel (>= 1.1.5)
|
25
25
|
rmagick (~> 2)
|
@@ -64,7 +64,7 @@ DEPENDENCIES
|
|
64
64
|
cucumber
|
65
65
|
daemon (~> 1)
|
66
66
|
httpclient (>= 2.2.1)
|
67
|
-
httpthumbnailer (~> 0.0.
|
67
|
+
httpthumbnailer (~> 0.0.7)
|
68
68
|
jeweler (~> 1.6.4)
|
69
69
|
rcov
|
70
70
|
rdoc (~> 3.9)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "httpthumbnailer-client"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jakub Pastuszek"]
|
12
|
-
s.date = "2011-11-
|
12
|
+
s.date = "2011-11-30"
|
13
13
|
s.description = "Thumbnails images using httpthumbniler server"
|
14
14
|
s.email = "jpastuszek@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"spec/httpthumbnailer-client_spec.rb",
|
34
34
|
"spec/multipart_response_spec.rb",
|
35
35
|
"spec/spec_helper.rb",
|
36
|
+
"spec/test-large.jpg",
|
36
37
|
"spec/test.jpg",
|
37
38
|
"spec/test.txt"
|
38
39
|
]
|
@@ -54,7 +55,7 @@ Gem::Specification.new do |s|
|
|
54
55
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
56
|
s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
|
56
57
|
s.add_development_dependency(%q<daemon>, ["~> 1"])
|
57
|
-
s.add_development_dependency(%q<httpthumbnailer>, ["~> 0.0.
|
58
|
+
s.add_development_dependency(%q<httpthumbnailer>, ["~> 0.0.7"])
|
58
59
|
else
|
59
60
|
s.add_dependency(%q<httpclient>, [">= 2.2.1"])
|
60
61
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
@@ -64,7 +65,7 @@ Gem::Specification.new do |s|
|
|
64
65
|
s.add_dependency(%q<rcov>, [">= 0"])
|
65
66
|
s.add_dependency(%q<rdoc>, ["~> 3.9"])
|
66
67
|
s.add_dependency(%q<daemon>, ["~> 1"])
|
67
|
-
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.
|
68
|
+
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.7"])
|
68
69
|
end
|
69
70
|
else
|
70
71
|
s.add_dependency(%q<httpclient>, [">= 2.2.1"])
|
@@ -75,7 +76,7 @@ Gem::Specification.new do |s|
|
|
75
76
|
s.add_dependency(%q<rcov>, [">= 0"])
|
76
77
|
s.add_dependency(%q<rdoc>, ["~> 3.9"])
|
77
78
|
s.add_dependency(%q<daemon>, ["~> 1"])
|
78
|
-
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.
|
79
|
+
s.add_dependency(%q<httpthumbnailer>, ["~> 0.0.7"])
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -6,6 +6,9 @@ class HTTPThumbnailerClient
|
|
6
6
|
class UnsupportedMediaTypeError < ArgumentError
|
7
7
|
end
|
8
8
|
|
9
|
+
class ImageTooLargeError < ArgumentError
|
10
|
+
end
|
11
|
+
|
9
12
|
class UnknownResponseType < ArgumentError
|
10
13
|
end
|
11
14
|
|
@@ -54,9 +57,10 @@ class HTTPThumbnailerClient
|
|
54
57
|
class ThumbnailingError
|
55
58
|
def initialize(msg)
|
56
59
|
@message = msg
|
60
|
+
@type = msg.match(/Error: (.*?): /)[1] rescue NoMethodError
|
57
61
|
end
|
58
62
|
|
59
|
-
attr_reader :message
|
63
|
+
attr_reader :type, :message
|
60
64
|
end
|
61
65
|
|
62
66
|
def initialize(server_url)
|
@@ -73,6 +77,8 @@ class HTTPThumbnailerClient
|
|
73
77
|
case response.status
|
74
78
|
when 415
|
75
79
|
raise UnsupportedMediaTypeError, response.body.delete("\r")
|
80
|
+
when 413
|
81
|
+
raise ImageTooLargeError, response.body.delete("\r")
|
76
82
|
else
|
77
83
|
raise RemoteServerError, response.body.delete("\r")
|
78
84
|
end
|
@@ -66,6 +66,15 @@ describe HTTPThumbnailerClient do
|
|
66
66
|
}.should raise_error HTTPThumbnailerClient::UnsupportedMediaTypeError
|
67
67
|
end
|
68
68
|
|
69
|
+
it "should raise HTTPThumbnailerClient::ImageTooLargeError error on too large image data to fit in memory limits" do
|
70
|
+
lambda {
|
71
|
+
HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((spec_dir + 'test-large.jpg').read) do
|
72
|
+
thumbnail 'crop', 6, 3, 'JPEG'
|
73
|
+
thumbnail 'crop', 8, 8, 'PNG'
|
74
|
+
end
|
75
|
+
}.should raise_error HTTPThumbnailerClient::ImageTooLargeError
|
76
|
+
end
|
77
|
+
|
69
78
|
it "should raise HTTPThumbnailerClient::RemoteServerError error on 404 server error" do
|
70
79
|
lambda {
|
71
80
|
HTTPThumbnailerClient.new('http://localhost:3100/blah').thumbnail((spec_dir + 'test.jpg').read) do
|
@@ -89,6 +98,7 @@ describe HTTPThumbnailerClient do
|
|
89
98
|
i.height.should == 3
|
90
99
|
|
91
100
|
thumbs[1].should be_kind_of HTTPThumbnailerClient::ThumbnailingError
|
101
|
+
thumbs[1].type.should == "ArgumentError"
|
92
102
|
thumbs[1].message.should == "Error: ArgumentError: invalid result dimension (0, 0 given)\n"
|
93
103
|
|
94
104
|
thumbs[2].should be_kind_of HTTPThumbnailerClient::Thumbnail
|
@@ -98,5 +108,31 @@ describe HTTPThumbnailerClient do
|
|
98
108
|
i.width.should == 4
|
99
109
|
i.height.should == 4
|
100
110
|
end
|
111
|
+
|
112
|
+
it "should return HTTPThumbnailerClient::ThumbnailingError object with set of returned thumbnail in case of memory exhaustion while thumbnailing" do
|
113
|
+
thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((spec_dir + 'test.jpg').read) do
|
114
|
+
thumbnail 'crop', 6, 3, 'JPEG'
|
115
|
+
thumbnail 'crop', 16000, 16000, 'PNG'
|
116
|
+
thumbnail 'crop', 4, 4, 'PNG'
|
117
|
+
end
|
118
|
+
|
119
|
+
thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
|
120
|
+
thumbs[0].mime_type.should == 'image/jpeg'
|
121
|
+
i = identify(thumbs[0].data)
|
122
|
+
i.format.should == 'JPEG'
|
123
|
+
i.width.should == 6
|
124
|
+
i.height.should == 3
|
125
|
+
|
126
|
+
thumbs[1].should be_kind_of HTTPThumbnailerClient::ThumbnailingError
|
127
|
+
thumbs[1].type.should == "Thumbnailer::ImageTooLargeError"
|
128
|
+
thumbs[1].message.should =~ /^Error: Thumbnailer::ImageTooLargeError:/
|
129
|
+
|
130
|
+
thumbs[2].should be_kind_of HTTPThumbnailerClient::Thumbnail
|
131
|
+
thumbs[2].mime_type.should == 'image/png'
|
132
|
+
i = identify(thumbs[2].data)
|
133
|
+
i.format.should == 'PNG'
|
134
|
+
i.width.should == 4
|
135
|
+
i.height.should == 4
|
136
|
+
end
|
101
137
|
end
|
102
138
|
|
data/spec/test-large.jpg
ADDED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpthumbnailer-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jakub Pastuszek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -145,12 +145,12 @@ dependencies:
|
|
145
145
|
requirements:
|
146
146
|
- - ~>
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
hash:
|
148
|
+
hash: 17
|
149
149
|
segments:
|
150
150
|
- 0
|
151
151
|
- 0
|
152
|
-
-
|
153
|
-
version: 0.0.
|
152
|
+
- 7
|
153
|
+
version: 0.0.7
|
154
154
|
prerelease: false
|
155
155
|
name: httpthumbnailer
|
156
156
|
version_requirements: *id009
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- spec/httpthumbnailer-client_spec.rb
|
181
181
|
- spec/multipart_response_spec.rb
|
182
182
|
- spec/spec_helper.rb
|
183
|
+
- spec/test-large.jpg
|
183
184
|
- spec/test.jpg
|
184
185
|
- spec/test.txt
|
185
186
|
homepage: http://github.com/jpastuszek/httpthumbnailer-client
|