authentic-image 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 894c81531772fbbc2f431a98944d9fc835d47871
4
+ data.tar.gz: 4e1f2e285e7666dc581e1d09ece19ec25dea5690
5
+ SHA512:
6
+ metadata.gz: 6effdfb9dd3d231722ba3d758f9bbb404a6a8d13e41aab2004bcb5cc14e3db7739229201c879c09a40325e5c5272e9b38c775d0990c183845140ba0a59722a3d
7
+ data.tar.gz: 91469dc56811ac72e11f67bec626dba2580ea32ae4e2512fbf042e5df3be9e0051ecb2769d96600f283b53550cc38ab6c46304587e07fb72e511cbc5eaf1cedf
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /Gemfile.lock
7
+ /jars/*.jar
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,49 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - "bin/**/*"
5
+ - "vendor/**/*"
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+ Style/WordArray:
9
+ Enabled: false
10
+ Metrics/LineLength:
11
+ Enabled: false
12
+ Style/TrailingCommaInLiteral:
13
+ Enabled: false
14
+ Style/TrailingCommaInArguments:
15
+ Enabled: false
16
+ Style/EmptyLinesAroundClassBody:
17
+ Enabled: false
18
+ Style/EmptyLinesAroundModuleBody:
19
+ Enabled: false
20
+ Style/EmptyLinesAroundBlockBody:
21
+ Enabled: false
22
+ Style/CaseIndentation:
23
+ Enabled: false
24
+ Style/Documentation:
25
+ Enabled: false
26
+ Style/MultilineOperationIndentation:
27
+ EnforcedStyle: indented
28
+ Style/RegexpLiteral:
29
+ Enabled: false
30
+ Style/IfUnlessModifier:
31
+ Enabled: false
32
+ Style/TrivialAccessors:
33
+ AllowPredicates: true
34
+ Style/BracesAroundHashParameters:
35
+ Enabled: false
36
+ Style/IndentHash:
37
+ Enabled: false
38
+ Style/NumericLiterals:
39
+ Enabled: false
40
+ Style/ExtraSpacing:
41
+ Enabled: false
42
+ Style/DotPosition:
43
+ Enabled: false
44
+ Style/SpaceInsideBlockBraces:
45
+ Enabled: false
46
+ Style/SpaceInsideHashLiteralBraces:
47
+ Enabled: false
48
+ Style/AlignHash:
49
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.3
@@ -0,0 +1,3 @@
1
+ sudo: false
2
+ language: ruby
3
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
@@ -0,0 +1,25 @@
1
+ # AuthenticImage
2
+
3
+ TODO
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "authentic-image"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ TODO: Write usage instructions here
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
+
21
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mytours/authentic-image.
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+
10
+ Dir.glob("./lib/tasks/**/*.rake").each { |r| import r }
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "authentic_image/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "authentic-image"
10
+ spec.version = AuthenticImage::VERSION
11
+ spec.authors = ["Authentic Limited"]
12
+ spec.email = ["rubygems@kotiri.com"]
13
+
14
+ spec.summary = "Image client for Authentic Apps"
15
+ spec.description = spec.summary
16
+ spec.homepage = "https://github.com/mytours/authentic-image"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "awesome_print"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rubocop"
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "authentic-image"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "authentic_image/version"
4
+ require "authentic_image/client"
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "cgi"
5
+ require "openssl"
6
+ require "authentic_image/request"
7
+
8
+ module AuthenticImage
9
+ class Client
10
+ PATH_PATTERN = %r{
11
+ (?<prefix>[\w_\-/]+)/
12
+ (?<identifier>[\w~%_\-\.]+)/
13
+ (?<region>[\w!,:]+)/
14
+ (?<size>[\w!,:]+)/
15
+ (?<rotation>[\w!]+)/
16
+ (?<quality>[\w]+)\.
17
+ (?<format>[\w]+)
18
+ }x
19
+
20
+ def initialize(host:, prefix: "/iiif/2", signing_key:, digest: "sha1")
21
+ @host = host
22
+ @prefix = prefix
23
+ @signing_key = signing_key
24
+ @digest = digest
25
+ end
26
+
27
+ attr_reader :host, :prefix, :signing_key, :digest
28
+
29
+ def request(**kwargs)
30
+ Request.new(
31
+ host: host,
32
+ prefix: prefix,
33
+ signing_key: signing_key,
34
+ **kwargs
35
+ )
36
+ end
37
+
38
+ def url(**kwargs)
39
+ request(**kwargs).url
40
+ end
41
+
42
+ def parse_url(url)
43
+ uri = URI(url)
44
+
45
+ path_match = PATH_PATTERN.match(uri.path)
46
+ return unless path_match
47
+
48
+ bucket, key = CGI.unescape(path_match[:identifier]).split("/", 2)
49
+
50
+ params = CGI.parse(uri.query)
51
+ version = params["ver"].first if params["ver"]
52
+
53
+ Request.new(
54
+ host: "#{uri.scheme}://#{uri.host}",
55
+ prefix: path_match[:prefix],
56
+ signing_key: signing_key,
57
+ bucket: bucket,
58
+ key: key,
59
+ size: path_match[:size],
60
+ format: path_match[:format],
61
+ region: path_match[:region],
62
+ rotation: path_match[:rotation],
63
+ quality: path_match[:quality],
64
+ version: version
65
+ )
66
+ end
67
+
68
+ def valid?(url)
69
+ request = parse_url(url)
70
+ return false unless request
71
+
72
+ uri = URI(url)
73
+ params = CGI.parse(uri.query)
74
+ return false unless params["sig"]
75
+
76
+ params["sig"].first == request.signature
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuthenticImage
4
+ # http://iiif.io/api/image/2.1/
5
+ class Request
6
+ def initialize(host:, prefix:, signing_key:, digest: "sha1", bucket:, key:, region: "full", size: "full", rotation: "0", quality: "default", format: "jpg", version: 1)
7
+ @host = host
8
+ @prefix = prefix
9
+ @signing_key = signing_key
10
+ @digest = OpenSSL::Digest.new(digest)
11
+ @bucket = bucket
12
+ @key = key
13
+ @region = region
14
+ @size = size
15
+ @rotation = rotation
16
+ @quality = quality
17
+ @format = format
18
+ @version = version
19
+ end
20
+
21
+ attr_reader :host, :prefix
22
+
23
+ attr_reader :bucket, :key
24
+
25
+ attr_reader :region
26
+
27
+ attr_reader :size
28
+
29
+ attr_reader :rotation
30
+
31
+ attr_reader :quality
32
+
33
+ attr_reader :format
34
+
35
+ attr_reader :version
36
+
37
+ def identifier
38
+ CGI.escape("#{bucket}/#{key}")
39
+ end
40
+
41
+ def path
42
+ "#{prefix}/#{identifier}/#{region}/#{size}/#{rotation}/#{quality}.#{format}"
43
+ end
44
+
45
+ def signature
46
+ OpenSSL::HMAC.hexdigest(digest, signing_key, path)
47
+ end
48
+
49
+ def url
50
+ "#{host}#{path}?sig=#{signature}&ver=#{version}"
51
+ end
52
+
53
+ def to_s
54
+ url
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :digest, :signing_key
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuthenticImage
4
+ VERSION = "0.0.1"
5
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authentic-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Authentic Limited
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Image client for Authentic Apps
98
+ email:
99
+ - rubygems@kotiri.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - authentic-image.gemspec
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/authentic-image.rb
116
+ - lib/authentic_image/client.rb
117
+ - lib/authentic_image/request.rb
118
+ - lib/authentic_image/version.rb
119
+ homepage: https://github.com/mytours/authentic-image
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Image client for Authentic Apps
142
+ test_files: []