riiif 0.4.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +26 -34
- data/.travis.yml +4 -1
- data/README.md +3 -3
- data/app/controllers/riiif/images_controller.rb +9 -3
- data/app/models/riiif/image.rb +5 -2
- data/lib/riiif/abstract_file_system_resolver.rb +1 -2
- data/lib/riiif/file_system_file_resolver.rb +1 -1
- data/lib/riiif/nil_authorization_service.rb +1 -2
- data/lib/riiif/routes.rb +1 -1
- data/lib/riiif/version.rb +1 -1
- data/riiif.gemspec +1 -1
- data/spec/controllers/riiif/images_controller_spec.rb +15 -15
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cbaa7e8d7dc7e47f05b3ed955c3710c8775faac
|
4
|
+
data.tar.gz: 7a3564aee52673c50d30999b07aedf6543eaa854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9dbd8ff0384e995595dca5bba8a8feb17a71535664cc79b5dba36fd2b55940ffe1ff80f2cbe68080c8177d2c54d9aea8480a51f0dff623647ad5885c681a1e
|
7
|
+
data.tar.gz: ae18e3a8d769bb6f1f130b87b9ed9bc78af32887839d3e54cb60e770e8cd8e884b89f4ec629f9e725ab40dc5421cee31cc750f08a356ea7b02043428110f2d29
|
data/.rubocop_todo.yml
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require: rubocop-rspec
|
2
1
|
# This configuration was generated by
|
3
2
|
# `rubocop --auto-gen-config`
|
4
|
-
# on
|
3
|
+
# on 2017-01-24 17:33:24 -0500 using RuboCop version 0.47.0.
|
5
4
|
# The point is for the user to remove these configuration records
|
6
5
|
# one by one as the offenses are removed from the code base.
|
7
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -25,16 +24,26 @@ Lint/UselessAssignment:
|
|
25
24
|
Exclude:
|
26
25
|
- 'app/models/riiif/file.rb'
|
27
26
|
|
28
|
-
# Offense count:
|
27
|
+
# Offense count: 4
|
29
28
|
Metrics/AbcSize:
|
30
|
-
Max:
|
29
|
+
Max: 38
|
30
|
+
|
31
|
+
# Offense count: 12
|
32
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
33
|
+
Metrics/BlockLength:
|
34
|
+
Max: 143
|
31
35
|
|
32
36
|
# Offense count: 1
|
37
|
+
# Configuration parameters: CountComments.
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 103
|
40
|
+
|
41
|
+
# Offense count: 2
|
33
42
|
Metrics/CyclomaticComplexity:
|
34
43
|
Max: 8
|
35
44
|
|
36
|
-
# Offense count:
|
37
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
45
|
+
# Offense count: 68
|
46
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
38
47
|
# URISchemes: http, https
|
39
48
|
Metrics/LineLength:
|
40
49
|
Max: 160
|
@@ -42,9 +51,9 @@ Metrics/LineLength:
|
|
42
51
|
# Offense count: 7
|
43
52
|
# Configuration parameters: CountComments.
|
44
53
|
Metrics/MethodLength:
|
45
|
-
Max:
|
54
|
+
Max: 21
|
46
55
|
|
47
|
-
# Offense count:
|
56
|
+
# Offense count: 2
|
48
57
|
Metrics/PerceivedComplexity:
|
49
58
|
Max: 9
|
50
59
|
|
@@ -54,26 +63,11 @@ Performance/RedundantMatch:
|
|
54
63
|
Exclude:
|
55
64
|
- 'lib/riiif/file_system_file_resolver.rb'
|
56
65
|
|
57
|
-
# Offense count: 1
|
58
|
-
RSpec/DescribeClass:
|
59
|
-
Exclude:
|
60
|
-
- 'spec/routing/resize_routes_spec.rb'
|
61
|
-
|
62
|
-
# Offense count: 6
|
63
|
-
# Configuration parameters: Max.
|
64
|
-
RSpec/ExampleLength:
|
65
|
-
Exclude:
|
66
|
-
- 'spec/controllers/riiif/images_controller_spec.rb'
|
67
|
-
- 'spec/models/riiif/http_file_resolver_spec.rb'
|
68
|
-
|
69
|
-
# Offense count: 4
|
70
|
-
RSpec/VerifiedDoubles:
|
71
|
-
Exclude:
|
72
|
-
- 'spec/controllers/riiif/images_controller_spec.rb'
|
73
|
-
|
74
66
|
# Offense count: 3
|
75
67
|
# Cop supports --auto-correct.
|
76
|
-
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
68
|
+
# Configuration parameters: EnforcedHashRocketStyle, SupportedHashRocketStyles, EnforcedColonStyle, SupportedColonStyles, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
69
|
+
# SupportedHashRocketStyles: key, separator, table
|
70
|
+
# SupportedColonStyles: key, separator, table
|
77
71
|
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
78
72
|
Style/AlignHash:
|
79
73
|
Exclude:
|
@@ -100,7 +94,7 @@ Style/ColonMethodCall:
|
|
100
94
|
Exclude:
|
101
95
|
- 'lib/riiif/http_file_resolver.rb'
|
102
96
|
|
103
|
-
# Offense count:
|
97
|
+
# Offense count: 14
|
104
98
|
Style/Documentation:
|
105
99
|
Exclude:
|
106
100
|
- 'spec/**/*'
|
@@ -109,6 +103,7 @@ Style/Documentation:
|
|
109
103
|
- 'app/models/riiif/file.rb'
|
110
104
|
- 'app/models/riiif/image.rb'
|
111
105
|
- 'lib/riiif.rb'
|
106
|
+
- 'lib/riiif/abstract_file_system_resolver.rb'
|
112
107
|
- 'lib/riiif/akubra_system_file_resolver.rb'
|
113
108
|
- 'lib/riiif/engine.rb'
|
114
109
|
- 'lib/riiif/file_system_file_resolver.rb'
|
@@ -117,26 +112,24 @@ Style/Documentation:
|
|
117
112
|
- 'lib/riiif/rails/routes.rb'
|
118
113
|
- 'lib/riiif/routes.rb'
|
119
114
|
|
120
|
-
# Offense count:
|
115
|
+
# Offense count: 2
|
121
116
|
# Cop supports --auto-correct.
|
122
117
|
Style/EmptyLines:
|
123
118
|
Exclude:
|
124
119
|
- 'app/models/riiif/image.rb'
|
125
|
-
- 'lib/riiif/file_system_file_resolver.rb'
|
126
120
|
- 'lib/riiif/http_file_resolver.rb'
|
127
121
|
|
128
|
-
# Offense count:
|
122
|
+
# Offense count: 5
|
129
123
|
# Cop supports --auto-correct.
|
130
124
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
131
|
-
# SupportedStyles: empty_lines, no_empty_lines
|
125
|
+
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
|
132
126
|
Style/EmptyLinesAroundClassBody:
|
133
127
|
Exclude:
|
134
128
|
- 'app/models/riiif/file.rb'
|
135
129
|
- 'app/models/riiif/image.rb'
|
136
|
-
- 'lib/riiif/file_system_file_resolver.rb'
|
137
130
|
- 'lib/riiif/http_file_resolver.rb'
|
138
131
|
|
139
|
-
# Offense count:
|
132
|
+
# Offense count: 5
|
140
133
|
# Cop supports --auto-correct.
|
141
134
|
Style/EmptyLinesAroundMethodBody:
|
142
135
|
Exclude:
|
@@ -150,4 +143,3 @@ Style/EmptyLinesAroundMethodBody:
|
|
150
143
|
Style/ExtraSpacing:
|
151
144
|
Exclude:
|
152
145
|
- 'lib/riiif/routes.rb'
|
153
|
-
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -7,13 +7,13 @@ A Ruby IIIF image server as a rails engine
|
|
7
7
|
|
8
8
|
RIIIF depends on Imagemagick so you must install that first. On a mac using Homebrew you can follow these instructions:
|
9
9
|
|
10
|
-
ImageMagick (
|
10
|
+
ImageMagick (7.0.4) may be installed with a few options:
|
11
11
|
* `--with-ghostscript` Compile with Ghostscript for Postscript/PDF support
|
12
12
|
* `--with-tiff` Compile with libtiff support for TIFF files
|
13
|
-
* `--with-
|
13
|
+
* `--with-openjpeg` Compile with openjpeg2 support for jpeg2000
|
14
14
|
|
15
15
|
```bash
|
16
|
-
brew install imagemagick --with-ghostscript --with-tiff --with-
|
16
|
+
brew install imagemagick --with-ghostscript --with-tiff --with-openjpeg
|
17
17
|
```
|
18
18
|
|
19
19
|
## Install the gem
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Riiif
|
2
2
|
class ImagesController < ::ApplicationController
|
3
|
-
|
3
|
+
before_action :link_header, only: [:show, :info]
|
4
4
|
|
5
5
|
rescue_from Riiif::InvalidAttributeError do
|
6
|
-
|
6
|
+
head 400
|
7
7
|
end
|
8
8
|
|
9
9
|
def show
|
@@ -20,7 +20,7 @@ module Riiif
|
|
20
20
|
|
21
21
|
image = not_found_image unless status == :ok
|
22
22
|
|
23
|
-
data = image.render(
|
23
|
+
data = image.render(image_request_params)
|
24
24
|
headers['Access-Control-Allow-Origin'] = '*'
|
25
25
|
send_data data,
|
26
26
|
status: status,
|
@@ -56,6 +56,12 @@ module Riiif
|
|
56
56
|
params[:id]
|
57
57
|
end
|
58
58
|
|
59
|
+
##
|
60
|
+
# @return [ActiveSupport::HashWithIndifferentAccess]
|
61
|
+
def image_request_params
|
62
|
+
params.permit(:region, :size, :rotation, :quality, :format).to_h
|
63
|
+
end
|
64
|
+
|
59
65
|
def authorization_service
|
60
66
|
model.authorization_service.new(self)
|
61
67
|
end
|
data/app/models/riiif/image.rb
CHANGED
@@ -32,6 +32,8 @@ module Riiif
|
|
32
32
|
@image ||= file_resolver.find(id)
|
33
33
|
end
|
34
34
|
|
35
|
+
##
|
36
|
+
# @param [ActiveSupport::HashWithIndifferentAccess] args
|
35
37
|
def render(args)
|
36
38
|
options = decode_options!(args)
|
37
39
|
Rails.cache.fetch(Image.cache_key(id, options), compress: true, expires_in: Image.expires_in) do
|
@@ -58,8 +60,9 @@ module Riiif
|
|
58
60
|
|
59
61
|
private
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
+
##
|
64
|
+
# @param [ActiveSupport::HashWithIndifferentAccess] options
|
65
|
+
def decode_options!(options)
|
63
66
|
raise ArgumentError, 'You must provide a format' unless options[:format]
|
64
67
|
options[:crop] = decode_region(options.delete(:region))
|
65
68
|
options[:size] = decode_size(options.delete(:size))
|
@@ -3,7 +3,7 @@ module Riiif
|
|
3
3
|
attr_writer :input_types
|
4
4
|
|
5
5
|
def pattern(id)
|
6
|
-
raise ArgumentError, "Invalid characters in id `#{id}`" unless
|
6
|
+
raise ArgumentError, "Invalid characters in id `#{id}`" unless /^[\w\-:]+$/.match(id)
|
7
7
|
::File.join(base_path, "#{id}.{#{input_types.join(',')}}")
|
8
8
|
end
|
9
9
|
|
data/lib/riiif/routes.rb
CHANGED
@@ -26,7 +26,7 @@ module Riiif
|
|
26
26
|
|
27
27
|
# This doesn't work presently
|
28
28
|
# get "#{route_prefix}/:id", to: redirect("#{route_prefix}/%{id}/info.json")
|
29
|
-
get "#{route_prefix}/:id" => 'riiif/images#redirect'
|
29
|
+
get "#{route_prefix}/:id" => 'riiif/images#redirect', as: [options[:as], 'base'].compact.join('_')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/riiif/version.rb
CHANGED
data/riiif.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'railties', '>= 4.2', '<6'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'engine_cart', '~> 0.8'
|
@@ -12,8 +12,8 @@ describe Riiif::ImagesController do
|
|
12
12
|
expect(image).to receive(:render).with('region' => 'full', 'size' => 'full',
|
13
13
|
'rotation' => '0', 'quality' => 'default',
|
14
14
|
'format' => 'jpg').and_return('IMAGEDATA')
|
15
|
-
get :show, id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
16
|
-
|
15
|
+
get :show, params: { id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
16
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
17
17
|
expect(response).to be_successful
|
18
18
|
expect(response.body).to eq 'IMAGEDATA'
|
19
19
|
expect(response.headers['Link']).to eq '<http://iiif.io/api/image/2/level1.json>;rel="profile"'
|
@@ -28,8 +28,8 @@ describe Riiif::ImagesController do
|
|
28
28
|
allow(controller).to receive(:not_found_image).and_return(not_found_image)
|
29
29
|
end
|
30
30
|
it 'renders 401' do
|
31
|
-
get :show, id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
32
|
-
|
31
|
+
get :show, params: { id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
32
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
33
33
|
expect(response.body).to eq 'test data'
|
34
34
|
expect(response.code).to eq '401'
|
35
35
|
end
|
@@ -40,8 +40,8 @@ describe Riiif::ImagesController do
|
|
40
40
|
image = double('an image')
|
41
41
|
allow(image).to receive(:render).and_raise Riiif::InvalidAttributeError
|
42
42
|
allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
43
|
-
get :show, id: 'abcd1234', action: 'show', region: '`szoW0', size: 'full',
|
44
|
-
|
43
|
+
get :show, params: { id: 'abcd1234', action: 'show', region: '`szoW0', size: 'full',
|
44
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
45
45
|
expect(response.code).to eq '400'
|
46
46
|
end
|
47
47
|
end
|
@@ -50,8 +50,8 @@ describe Riiif::ImagesController do
|
|
50
50
|
it "errors when a default image isn't sent" do
|
51
51
|
expect(Riiif::Image).to receive(:new).with('bad_id').and_raise(OpenURI::HTTPError.new('fail', StringIO.new))
|
52
52
|
expect do
|
53
|
-
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
54
|
-
|
53
|
+
get :show, params: { id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
54
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
55
55
|
end.to raise_error(StandardError)
|
56
56
|
end
|
57
57
|
|
@@ -73,8 +73,8 @@ describe Riiif::ImagesController do
|
|
73
73
|
'rotation' => '0', 'quality' => 'default',
|
74
74
|
'format' => 'jpg').and_return('default-image-data')
|
75
75
|
|
76
|
-
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
77
|
-
|
76
|
+
get :show, params: { id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
77
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
78
78
|
expect(response).to be_not_found
|
79
79
|
expect(response.body).to eq 'default-image-data'
|
80
80
|
end
|
@@ -89,8 +89,8 @@ describe Riiif::ImagesController do
|
|
89
89
|
'rotation' => '0', 'quality' => 'default',
|
90
90
|
'format' => 'jpg').and_return('default-image-data')
|
91
91
|
|
92
|
-
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
93
|
-
|
92
|
+
get :show, params: { id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
93
|
+
rotation: '0', quality: 'default', format: 'jpg' }
|
94
94
|
expect(response).to be_not_found
|
95
95
|
expect(response.body).to eq 'default-image-data'
|
96
96
|
end
|
@@ -103,11 +103,11 @@ describe Riiif::ImagesController do
|
|
103
103
|
image = double
|
104
104
|
expect(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
105
105
|
expect(image).to receive(:info).and_return(width: 6000, height: 4000)
|
106
|
-
get :info, id: 'abcd1234', format: 'json'
|
106
|
+
get :info, params: { id: 'abcd1234', format: 'json' }
|
107
107
|
expect(response).to be_successful
|
108
108
|
json = JSON.parse(response.body)
|
109
109
|
expect(json).to eq '@context' => 'http://iiif.io/api/image/2/context.json',
|
110
|
-
'@id' => 'http://test.host/
|
110
|
+
'@id' => 'http://test.host/abcd1234',
|
111
111
|
'width' => 6000,
|
112
112
|
'height' => 4000,
|
113
113
|
'profile' => ['http://iiif.io/api/image/2/level1.json', 'formats' => %w(jpg png)],
|
@@ -123,7 +123,7 @@ describe Riiif::ImagesController do
|
|
123
123
|
allow(controller).to receive(:authorization_service).and_return(auth)
|
124
124
|
end
|
125
125
|
it 'renders 401' do
|
126
|
-
get :info, id: 'abcd1234', format: 'json'
|
126
|
+
get :info, params: { id: 'abcd1234', format: 'json' }
|
127
127
|
expect(response.body).to eq '{"error":"unauthorized"}'
|
128
128
|
expect(response.code).to eq '401'
|
129
129
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riiif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '6'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '6'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
190
|
version: '0'
|
185
191
|
requirements: []
|
186
192
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.5.
|
193
|
+
rubygems_version: 2.5.2
|
188
194
|
signing_key:
|
189
195
|
specification_version: 4
|
190
196
|
summary: A rails engine that support IIIF requests
|