Skip to content

Commit

Permalink
Switch native-> default for API 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 6, 2015
1 parent 82b25b0 commit b2f7345
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -12,5 +12,5 @@ lib/bundler/man
pkg
rdoc
spec/reports
spec/internal
.internal_test_app
tmp
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -72,12 +72,12 @@ Add the routes to your application by inserting the following line into `config/

Then you can make requests like this:

* http://www.example.org/image-service/abcd1234/full/full/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/100,/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/,100/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/pct:50/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/150,75/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/!150,75/0/native.jpg
* http://www.example.org/image-service/abcd1234/full/full/0/default.jpg
* http://www.example.org/image-service/abcd1234/full/100,/0/default.jpg
* http://www.example.org/image-service/abcd1234/full/,100/0/default.jpg
* http://www.example.org/image-service/abcd1234/full/pct:50/0/default.jpg
* http://www.example.org/image-service/abcd1234/full/150,75/0/default.jpg
* http://www.example.org/image-service/abcd1234/full/!150,75/0/default.jpg

### Route helpers

Expand Down
2 changes: 1 addition & 1 deletion app/models/riiif/image.rb
Expand Up @@ -69,7 +69,7 @@ def decode_options!(args)
end

def decode_quality(quality)
return if quality.nil? || ['native', 'color'].include?(quality)
return if quality.nil? || ['default', 'color'].include?(quality)
return quality if ['bitonal', 'grey'].include?(quality)
raise InvalidAttributeError, "Unsupported quality: #{quality}"
end
Expand Down
3 changes: 1 addition & 2 deletions lib/riiif/akubra_system_file_resolver.rb
Expand Up @@ -27,8 +27,7 @@ def pattern(id)
directorystr = ""
@akubraconfig.each { |a| directorystr << digest[a[0],a[1]] << "/" }
filename = CGI.escape(fullpid)
fullpath = @pathroot + directorystr + filename
fullpath
@pathroot + directorystr + filename
end
end
end
4 changes: 2 additions & 2 deletions lib/riiif/routes.rb
Expand Up @@ -19,11 +19,11 @@ def draw
route_prefix ||= "/#{options[:as]}" if options[:as]
get "#{route_prefix}/:id/:region/:size/:rotation/:quality.:format" => "riiif/images#show",
constraints: { rotation: ALLOW_DOTS, size: SIZES },
defaults: { format: 'jpg', rotation: '0', region: 'full', quality: 'native', model: resource },
defaults: { format: 'jpg', rotation: '0', region: 'full', quality: 'default', model: resource },
as: options[:as] || "image"

get "#{route_prefix}/:id/info.json" => "riiif/images#info", defaults: { format: 'json', model: resource }, as: [options[:as], "info"].compact.join("_")
end
end
end
end
end
2 changes: 1 addition & 1 deletion riiif.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "engine_cart"
spec.add_development_dependency "engine_cart", '~> 0.8'
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "sqlite3"
spec.add_dependency 'rails', '> 3.2.0'
Expand Down
16 changes: 8 additions & 8 deletions spec/controllers/images_controller_spec.rb
Expand Up @@ -8,10 +8,10 @@
image = double
expect(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
expect(image).to receive(:render).with("region" => 'full', "size" => 'full',
"rotation" => '0', "quality" => 'native',
"rotation" => '0', "quality" => 'default',
"format" => 'jpg').and_return("IMAGEDATA")
get :show, id: 'abcd1234', action: "show", region: 'full', size: 'full',
rotation: '0', quality: 'native', format: 'jpg'
rotation: '0', quality: 'default', format: 'jpg'
expect(response).to be_successful
expect(response.body).to eq 'IMAGEDATA'
expect(response.headers['Link']).to eq '<http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2>;rel="profile"'
Expand All @@ -38,7 +38,7 @@
expect(Riiif::Image).to receive(:new).with('bad_id').and_raise(OpenURI::HTTPError.new("fail", StringIO.new))
expect do
get :show, id: 'bad_id', action: "show", region: 'full', size: 'full',
rotation: '0', quality: 'native', format: 'jpg'
rotation: '0', quality: 'default', format: 'jpg'
end.to raise_error(StandardError)
end

Expand All @@ -60,11 +60,11 @@
end
end.twice
expect(not_found_image).to receive(:render).with("region" => 'full', "size" => 'full',
"rotation" => '0', "quality" => 'native',
"rotation" => '0', "quality" => 'default',
"format" => 'jpg').and_return("default-image-data")

get :show, id: 'bad_id', action: "show", region: 'full', size: 'full',
rotation: '0', quality: 'native', format: 'jpg'
rotation: '0', quality: 'default', format: 'jpg'
expect(response).to be_not_found
expect(response.body).to eq 'default-image-data'
end
Expand All @@ -79,11 +79,11 @@
end
end.twice
expect(not_found_image).to receive(:render).with("region" => 'full', "size" => 'full',
"rotation" => '0', "quality" => 'native',
"rotation" => '0', "quality" => 'default',
"format" => 'jpg').and_return("default-image-data")

get :show, id: 'bad_id', action: "show", region: 'full', size: 'full',
rotation: '0', quality: 'native', format: 'jpg'
get :show, id: 'bad_id', action: "show", region: 'full', size: 'full',
rotation: '0', quality: 'default', format: 'jpg'
expect(response).to be_not_found
expect(response.body).to eq 'default-image-data'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/akubra_system_file_resolver_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Riiif::AkubraSystemFileResolver do
subject { Riiif::AkubraSystemFileResolver.new(Rails.root.join('../../spec/samples/'),'jp2',[[0,2],[2,2],[4,1]]) }
subject { Riiif::AkubraSystemFileResolver.new(Rails.root.join('../spec/samples/'),'jp2',[[0,2],[2,2],[4,1]]) }
it "should raise an error when the file isn't found" do
expect{subject.find('demo:2')}.to raise_error Riiif::ImageNotFoundError
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/image_spec.rb
Expand Up @@ -35,7 +35,7 @@
before do
Riiif::Image.file_resolver = Riiif::HTTPFileResolver.new
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
"http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/#{id}.jpg/600px-#{id}.jpg"
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/#{id}.jpg/600px-#{id}.jpg"
end
end
after do
Expand Down Expand Up @@ -129,9 +129,9 @@
end

describe "quality" do
it "should return the original when specifing native" do
it "returns the original when specifing default" do
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
subject.render(quality: 'native', format: 'png')
subject.render(quality: 'default', format: 'png')
end
it "should return the original when specifing color" do
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
Expand Down
38 changes: 19 additions & 19 deletions spec/routing/resize_routes_spec.rb
Expand Up @@ -4,43 +4,43 @@
routes { Riiif::Engine.routes }

describe 'for conversion' do
it "routes GET /abcd1234/full/full/0/native.jpg" do
it "routes GET /abcd1234/full/full/0/default.jpg" do
expect(
get: "/abcd1234/full/full/0/native.jpg"
get: "/abcd1234/full/full/0/default.jpg"
).to route_to(controller: "riiif/images", id: 'abcd1234', action: "show",
region: 'full', size: 'full', rotation: '0',
quality: 'native', format: 'jpg', model: "riiif/image")
quality: 'default', format: 'jpg', model: "riiif/image")
end

it "routes requests with floating point percent size" do
expect(
get: "/abcd1234/full/pct:12.5/22.5/native.jpg"
).to route_to(controller: "riiif/images", id: 'abcd1234', action: "show",
region: 'full', size: 'pct:12.5', rotation: '22.5',
quality: 'native', format: 'jpg', model: "riiif/image")
get: "/abcd1234/full/pct:12.5/22.5/default.jpg"
).to route_to(controller: "riiif/images", id: 'abcd1234', action: "show",
region: 'full', size: 'pct:12.5', rotation: '22.5',
quality: 'default', format: 'jpg', model: "riiif/image")
end
it "routes requests with pixel size" do
expect(
get: "/abcd1234/full/100,50/22.5/native.jpg"
).to route_to(controller: "riiif/images", id: 'abcd1234', action: "show",
region: 'full', size: '100,50', rotation: '22.5',
quality: 'native', format: 'jpg', model: "riiif/image")
get: "/abcd1234/full/100,50/22.5/default.jpg"
).to route_to(controller: "riiif/images", id: 'abcd1234', action: "show",
region: 'full', size: '100,50', rotation: '22.5',
quality: 'default', format: 'jpg', model: "riiif/image")
end
it "routes requests with dashes in the id" do
expect(
get: "/abcd-1234-5678/full/full/0/native.jpg"
).to route_to(controller: "riiif/images", id: 'abcd-1234-5678', action: "show",
region: 'full', size: 'full', rotation: '0',
quality: 'native', format: 'jpg', model: "riiif/image")
get: "/abcd-1234-5678/full/full/0/default.jpg"
).to route_to(controller: "riiif/images", id: 'abcd-1234-5678', action: "show",
region: 'full', size: 'full', rotation: '0',
quality: 'default', format: 'jpg', model: "riiif/image")
end

describe "route helper" do
it "takes all the options" do
expect(image_path('abcd1234', region: 'full', size: '100,50', rotation: '22.5', quality: 'native',
format: 'jpg')).to eq '/abcd1234/full/100,50/22.5/native.jpg'
expect(image_path('abcd1234', region: 'full', size: '100,50', rotation: '22.5', quality: 'default',
format: 'jpg')).to eq '/abcd1234/full/100,50/22.5/default.jpg'
end
it "has defaults" do
expect(image_path('abcd1234', size: '100,50')).to eq '/abcd1234/full/100,50/0/native.jpg'
expect(image_path('abcd1234', size: '100,50')).to eq '/abcd1234/full/100,50/0/default.jpg'
end
end
end
Expand All @@ -49,7 +49,7 @@
it "routes GET /abcd1234/info.json" do
expect(
get: "/abcd1234/info.json"
).to route_to(controller: "riiif/images", id: 'abcd1234',
).to route_to(controller: "riiif/images", id: 'abcd1234',
action: "info", format: 'json', model: "riiif/image")
end
it "should have a route helper" do
Expand Down

0 comments on commit b2f7345

Please sign in to comment.