httpthumbnailer-client 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: ../httpthumbnailer
3
3
  specs:
4
- httpthumbnailer (1.1.0)
4
+ httpthumbnailer (1.2.0)
5
5
  rmagick (~> 2)
6
- unicorn-cuba-base (~> 1.1)
6
+ unicorn-cuba-base (~> 1.2.0)
7
7
 
8
8
  PATH
9
9
  remote: ../unicorn-cuba-base
10
10
  specs:
11
- unicorn-cuba-base (1.1.1)
11
+ unicorn-cuba-base (1.2.0)
12
12
  cli (~> 1.3)
13
13
  cuba (~> 3.0)
14
14
  facter (~> 1.6.11)
@@ -21,7 +21,7 @@ GEM
21
21
  specs:
22
22
  builder (3.0.0)
23
23
  cli (1.3.1)
24
- cuba (3.1.0)
24
+ cuba (3.1.1)
25
25
  rack
26
26
  cucumber (1.1.3)
27
27
  builder (>= 2.1.2)
@@ -42,10 +42,10 @@ GEM
42
42
  rake
43
43
  rdoc
44
44
  json (1.6.1)
45
- kgio (2.8.1)
45
+ kgio (2.9.2)
46
46
  multipart-parser (0.1.1)
47
47
  rack (1.5.2)
48
- raindrops (0.12.0)
48
+ raindrops (0.13.0)
49
49
  rake (10.0.4)
50
50
  rdoc (3.9.4)
51
51
  rmagick (2.13.2)
@@ -59,7 +59,7 @@ GEM
59
59
  rspec-mocks (2.13.1)
60
60
  ruby-ip (0.9.1)
61
61
  term-ansicolor (1.0.7)
62
- unicorn (4.6.3)
62
+ unicorn (4.8.2)
63
63
  kgio (~> 2.6)
64
64
  rack
65
65
  raindrops (~> 0.7)
data/README.md CHANGED
@@ -23,10 +23,10 @@ data = File.read('image_file.jpg')
23
23
 
24
24
  # generate single thumbnail from image data (single thumbnail API)
25
25
  thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail(data, 'crop', 60, 30, 'jpeg')
26
- thumbnail.mime_type # => 'image/jpeg'
27
- thumbnail.width # => 60
28
- thumbnail.height # => 30
29
- thumbnail.data # => 60x30 thumbnail JPEG data String
26
+ thumbnail.mime_type # => 'image/jpeg'
27
+ thumbnail.width # => 60
28
+ thumbnail.height # => 30
29
+ thumbnail.data # => 60x30 thumbnail JPEG data String
30
30
 
31
31
  # generate set of thumbnails from image data (multipart API)
32
32
  thumbnails = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail(data) do
@@ -35,30 +35,36 @@ thumbnails = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail(data)
35
35
  thumbnail 'pad', 40, 40, 'png'
36
36
  end
37
37
 
38
- thumbnails[0].mime_type # => 'image/jpeg'
39
- thumbnails[0].width # => 60
40
- thumbnails[0].height # => 30
41
- thumbnails[0].data # => 60x30 thumbnail JPEG data String
38
+ thumbnails[0].mime_type # => 'image/jpeg'
39
+ thumbnails[0].width # => 60
40
+ thumbnails[0].height # => 30
41
+ thumbnails[0].data # => 60x30 thumbnail JPEG data String
42
42
 
43
- thumbnails[1].mime_type # => 'image/png'
44
- thumbnails[1].width # => 80
45
- thumbnails[1].height # => 80
46
- thumbnails[1].data # => 80x80 thumbnail PNG data String
43
+ thumbnails[1].mime_type # => 'image/png'
44
+ thumbnails[1].width # => 80
45
+ thumbnails[1].height # => 80
46
+ thumbnails[1].data # => 80x80 thumbnail PNG data String
47
47
 
48
- thumbnails[2].mime_type # => 'image/png'
49
- thumbnails[2].width # => 40
50
- thumbnails[2].height # => 40
51
- thumbnails[2].data # => 40x40 thumbnail PNG data String
48
+ thumbnails[2].mime_type # => 'image/png'
49
+ thumbnails[2].width # => 40
50
+ thumbnails[2].height # => 40
51
+ thumbnails[2].data # => 40x40 thumbnail PNG data String
52
52
 
53
- thumbnails.input_mime_type # => 'image/jpeg' - detected input image format by API server (content based)
54
- thumbnails.input_width # => 800 - detected input image width by API server (content based)
55
- thumbnails.input_height # => 600 - detected input image height by API server (content based)
53
+ thumbnails.input_mime_type # => 'image/jpeg' - detected input image format by API server (content based)
54
+ thumbnails.input_width # => 800 - detected input image width by API server (content based)
55
+ thumbnails.input_height # => 600 - detected input image height by API server (content based)
56
56
 
57
57
  # just identify the image
58
58
  id = HTTPThumbnailerClient.new('http://localhost:3100').identify(data)
59
- id.mime_type # => 'image/jpeg'
60
- id.width # => 800
61
- id.height # => 600
59
+ id.mime_type # => 'image/jpeg'
60
+ id.width # => 800
61
+ id.height # => 600
62
+
63
+ # pass transaction ID header to thumbnailer
64
+ id = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => '123').identify(data)
65
+ id.mime_type # => 'image/jpeg'
66
+ id.width # => 800
67
+ id.height # => 600
62
68
  ```
63
69
 
64
70
  For more details see RSpec for [single thumbnail API](http://github.com/jpastuszek/httpthumbnailer-client/blob/master/spec/thumbnail_spec.rb) and [multipart API](http://github.com/jpastuszek/httpthumbnailer-client/blob/master/spec/thumbnails_spec.rb).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "httpthumbnailer-client"
8
- s.version = "1.1.1"
8
+ s.version = "1.2.0"
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 = "2013-10-07"
12
+ s.date = "2014-07-28"
13
13
  s.description = "Thumbnails images using httpthumbniler server"
14
14
  s.email = "jpastuszek@gmail.com"
15
15
  s.executables = ["httpthumbnailer-client"]
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.homepage = "http://github.com/jpastuszek/httpthumbnailer-client"
45
45
  s.licenses = ["MIT"]
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = "1.8.25"
47
+ s.rubygems_version = "1.8.23"
48
48
  s.summary = "API client for httpthumbniler server"
49
49
 
50
50
  if s.respond_to? :specification_version then
@@ -88,8 +88,8 @@ class HTTPThumbnailerClient
88
88
  args << format.to_s
89
89
 
90
90
  options.keys.sort{|a, b| a.to_s <=> b.to_s}.each do |key|
91
- raise InvalidThumbnailSpecificationError.new("empty option key for value '#{options[key]}'") if key.nil? || key.to_s.empty?
92
- raise InvalidThumbnailSpecificationError.new("missing option value for key '#{key}'") if options[key].nil? || options[key].to_s.empty?
91
+ raise InvalidThumbnailSpecificationError.new("empty option key for value '#{options[key]}'") if key.nil? || key.to_s.empty?
92
+ raise InvalidThumbnailSpecificationError.new("missing option value for key '#{key}'") if options[key].nil? || options[key].to_s.empty?
93
93
  args << "#{key}:#{options[key]}"
94
94
  end
95
95
 
@@ -106,7 +106,7 @@ class HTTPThumbnailerClient
106
106
  # added to thumbnailer v1.1.0 so may be nil for older server
107
107
  @width = width.to_i if width
108
108
  @height = height.to_i if height
109
- end
109
+ end
110
110
 
111
111
  attr_reader :mime_type
112
112
  attr_reader :width
@@ -143,6 +143,9 @@ class HTTPThumbnailerClient
143
143
  @client.send_timeout = options[:send_timeout] || 300
144
144
  @client.receive_timeout = options[:receive_timeout] || 300
145
145
 
146
+ # additional HTTP headers to be passed with requests
147
+ @headers = options[:headers] || {}
148
+
146
149
  # don't use keep alive by default since backend won't support it any way unless fronted with nginx or similar
147
150
  @keep_alive = options[:keep_alive] || false
148
151
  end
@@ -157,7 +160,7 @@ class HTTPThumbnailerClient
157
160
  URIBuilder.thumbnail(*spec)
158
161
  end
159
162
 
160
- response = @client.request('PUT', "#{@server_url}#{uri}", nil, data, {'Content-Type' => 'image/autodetect'})
163
+ response = @client.request('PUT', "#{@server_url}#{uri}", nil, data, {'Content-Type' => 'image/autodetect'}.merge(@headers))
161
164
  @client.reset_all unless @keep_alive
162
165
 
163
166
  content_type = response.header['Content-Type'].last
@@ -216,7 +219,7 @@ class HTTPThumbnailerClient
216
219
  end
217
220
 
218
221
  def identify(data)
219
- response = @client.request('PUT', "#{@server_url}/identify", nil, data, {'Content-Type' => 'image/autodetect'})
222
+ response = @client.request('PUT', "#{@server_url}/identify", nil, data, {'Content-Type' => 'image/autodetect'}.merge(@headers))
220
223
  @client.reset_all unless @keep_alive
221
224
 
222
225
  content_type = response.header['Content-Type'].last
@@ -235,6 +238,14 @@ class HTTPThumbnailerClient
235
238
  raise RemoteServerError, 'empty response'
236
239
  end
237
240
 
241
+ attr_accessor :headers
242
+
243
+ def with_headers(headers)
244
+ n = self.dup
245
+ n.headers = @headers.merge headers
246
+ n
247
+ end
248
+
238
249
  def inspect
239
250
  "#<#{self.class.name} server_url=#{server_url.inspect} keep_alive=#{keep_alive.inspect}>"
240
251
  end
@@ -4,7 +4,7 @@ describe HTTPThumbnailerClient, 'identify API' do
4
4
  before :all do
5
5
  log = support_dir + 'server.log'
6
6
  start_server(
7
- "httpthumbnailer -f -d -l #{log}",
7
+ "httpthumbnailer -f -d -x XID -l #{log}",
8
8
  '/tmp/httpthumbnailer.pid',
9
9
  log,
10
10
  'http://localhost:3100/'
@@ -29,5 +29,16 @@ describe HTTPThumbnailerClient, 'identify API' do
29
29
  }.should raise_error HTTPThumbnailerClient::UnsupportedMediaTypeError
30
30
  end
31
31
  end
32
+
33
+ describe 'passing custom HTTP request headers' do
34
+ it '#with_headers should add headers to given request' do
35
+ xid = rand(0..1000)
36
+
37
+ input_id = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).identify((support_dir + 'test.jpg').read)
38
+ input_id.mime_type.should == 'image/jpeg'
39
+
40
+ (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
41
+ end
42
+ end
32
43
  end
33
44
 
@@ -4,7 +4,7 @@ describe HTTPThumbnailerClient, 'single thumbnail API' do
4
4
  before :all do
5
5
  log = support_dir + 'server.log'
6
6
  start_server(
7
- "httpthumbnailer -f -d -l #{log}",
7
+ "httpthumbnailer -f -d -x XID -l #{log}",
8
8
  '/tmp/httpthumbnailer.pid',
9
9
  log,
10
10
  'http://localhost:3100/'
@@ -71,5 +71,32 @@ describe HTTPThumbnailerClient, 'single thumbnail API' do
71
71
  }.should raise_error HTTPThumbnailerClient::ImageTooLargeError
72
72
  end
73
73
  end
74
+
75
+ describe 'passing custom HTTP request headers' do
76
+ it 'should add headers provided with :headers option' do
77
+ xid = rand(0..1000)
78
+
79
+ thumbnail = HTTPThumbnailerClient.new('http://localhost:3100', headers: {'XID' => xid}).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
80
+ thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
81
+
82
+ (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
83
+ end
84
+
85
+ it '#with_headers should add headers to given request' do
86
+ xid = rand(0..1000)
87
+
88
+ thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
89
+ thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
90
+
91
+ (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
92
+
93
+ xid = rand(1000..2000)
94
+
95
+ thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
96
+ thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
97
+
98
+ (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
99
+ end
100
+ end
74
101
  end
75
102
 
@@ -4,7 +4,7 @@ describe HTTPThumbnailerClient, 'multipart API' do
4
4
  before :all do
5
5
  log = support_dir + 'server.log'
6
6
  start_server(
7
- "httpthumbnailer -f -d -l #{log}",
7
+ "httpthumbnailer -f -d -x XID -l #{log}",
8
8
  '/tmp/httpthumbnailer.pid',
9
9
  log,
10
10
  'http://localhost:3100/'
@@ -17,7 +17,7 @@ describe HTTPThumbnailerClient, 'multipart API' do
17
17
 
18
18
  it 'should return set of thumbnails matching specifications' do
19
19
  thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
20
- thumbnail 'crop', 60, 30, 'jpeg'
20
+ thumbnail 'crop', 60, 30, 'jpeg'
21
21
  thumbnail 'crop', 80, 80, 'png'
22
22
  thumbnail 'crop', 40, 40, 'png'
23
23
  end
@@ -53,14 +53,14 @@ describe HTTPThumbnailerClient, 'multipart API' do
53
53
  describe 'meta data' do
54
54
  it 'should provide input image mime type' do
55
55
  thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
56
- thumbnail 'crop', 6, 3, 'jpeg'
56
+ thumbnail 'crop', 6, 3, 'jpeg'
57
57
  end
58
58
  thumbs.input_mime_type.should == 'image/jpeg'
59
59
  end
60
60
 
61
61
  it 'should provide input image size' do
62
62
  thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
63
- thumbnail 'crop', 6, 3, 'jpeg'
63
+ thumbnail 'crop', 6, 3, 'jpeg'
64
64
  end
65
65
  thumbs.input_width.should == 509
66
66
  thumbs.input_height.should == 719
@@ -70,7 +70,7 @@ describe HTTPThumbnailerClient, 'multipart API' do
70
70
  describe 'returns HTTPThumbnailerClient::HTTPThumbnailerClientError object within set of returned thumbnails' do
71
71
  it 'in case of error with particluar thumbanil' do
72
72
  thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
73
- thumbnail 'crop', 6, 3, 'jpeg'
73
+ thumbnail 'crop', 6, 3, 'jpeg'
74
74
  thumbnail 'crop', 0, 0, 'png'
75
75
  thumbnail 'crop', 4, 4, 'png'
76
76
  end
@@ -96,7 +96,7 @@ describe HTTPThumbnailerClient, 'multipart API' do
96
96
 
97
97
  it 'in case of memory exhaustion while thumbnailing' do
98
98
  thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
99
- thumbnail 'crop', 6, 3, 'jpeg'
99
+ thumbnail 'crop', 6, 3, 'jpeg'
100
100
  thumbnail 'crop', 16000, 16000, 'png'
101
101
  thumbnail 'crop', 4, 4, 'png'
102
102
  end
@@ -120,5 +120,20 @@ describe HTTPThumbnailerClient, 'multipart API' do
120
120
  i.height.should == 4
121
121
  end
122
122
  end
123
+
124
+ describe 'passing custom HTTP request headers' do
125
+ it '#with_headers should add headers to given request' do
126
+ xid = rand(0..1000)
127
+
128
+ thumbs = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read) do
129
+ thumbnail 'crop', 60, 30, 'jpeg'
130
+ thumbnail 'crop', 80, 80, 'png'
131
+ thumbnail 'crop', 40, 40, 'png'
132
+ end
133
+ thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
134
+
135
+ (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
136
+ end
137
+ end
123
138
  end
124
139
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpthumbnailer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-07 00:00:00.000000000 Z
12
+ date: 2014-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -249,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
249
  version: '0'
250
250
  segments:
251
251
  - 0
252
- hash: -3857220952369386674
252
+ hash: 2965592177310199957
253
253
  required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  none: false
255
255
  requirements:
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubyforge_project:
261
- rubygems_version: 1.8.25
261
+ rubygems_version: 1.8.23
262
262
  signing_key:
263
263
  specification_version: 3
264
264
  summary: API client for httpthumbniler server