imageomatic 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f21da146260850a58131cbc1beff664ba283c6677e954c66da84e89d2674a8f
4
- data.tar.gz: 50c93f247027c69cc997d04cf06c8b6f96df98f0abd14f86aa40e577e66c80b5
3
+ metadata.gz: 7903eeab14e261a76042cba4e2a2127dc84bf4d1bb1c88d3cec3b2e8fddafa87
4
+ data.tar.gz: 336a739324d3dc2216e9089bebff9e1a47f513cc3049906a3b036d4a73529ab9
5
5
  SHA512:
6
- metadata.gz: 00060a525441bf8c6621073e1dc101d90dee901aa53951c992630ad3756d65afc84564285294f4734f9afa6b96182f1cd8226eb4fc24cc856dc43afa2f47b74e
7
- data.tar.gz: 1a1047e9e4bc9e443f3ee55507f2639530c414fb08d04f15829a0783bcebf74c1e4d79a3af0a75efa23b3aa3ca53d5a19e52a1f8f98ec68238be07ea35d47f1c
6
+ metadata.gz: e47c991db4e2d284a28853ab375864dc6d8a5cf12743c629694045ad7be2c822362797ebc3bc7afa15189c5154c7d98d68dc3f9ad4b97002781248e8134d0da5
7
+ data.tar.gz: 91a59cce1f7a876d4fec576c6f7560e043ff0ac996308370abad4403fe392594383a869bf77506bb19d37b5818451522565efded925a9d774a457879756fa6f1
@@ -1,3 +1,3 @@
1
1
  # Used to represent the HTML pages that will be converted into an
2
2
  # image and served up for open graph image previews.
3
- Mime::Type.register "text/html", :opengraph
3
+ Mime::Type.register_alias "text/html", :opengraph
@@ -0,0 +1,44 @@
1
+ require "openssl"
2
+ require "uri"
3
+
4
+ module Imageomatic
5
+ class UrlSignature
6
+ # Use for `OpenSSL::HMAC`
7
+ DIGEST = "SHA256".freeze
8
+
9
+ attr_reader :secret_key, :public_key, :path_prefix
10
+
11
+ def initialize(secret_key:, public_key:)
12
+ @secret_key = secret_key
13
+ @public_key = public_key
14
+ @path_prefix = File.join("/", "v1", public_key)
15
+ end
16
+
17
+ def signed_url(path)
18
+ URI.join("https://www.imageomatic.com/", signed_path(path))
19
+ end
20
+
21
+ def valid?(url)
22
+ path = URI(url).request_uri
23
+ version, account_key, signature, path = Regexp.new("/(v1)/(.+?)/(.+?)(/.+)").match(path).captures
24
+ signature == sign(path)
25
+ end
26
+
27
+ def url_for(path, **query)
28
+ path = URI(path).tap do |url|
29
+ url.path = path
30
+ url.query = query.to_query
31
+ end
32
+ signed_url path
33
+ end
34
+
35
+ private
36
+ def signed_path(path)
37
+ File.join(path_prefix, sign(File.join("/", path.to_s)), path.to_s)
38
+ end
39
+
40
+ def sign(data)
41
+ OpenSSL::HMAC.hexdigest(DIGEST, secret_key, data)
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Imageomatic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/imageomatic.rb CHANGED
@@ -2,5 +2,5 @@ require "imageomatic/version"
2
2
  require "imageomatic/engine"
3
3
 
4
4
  module Imageomatic
5
- # Your code goes here...
5
+ autoload :UrlSignature, "imageomatic/url_signature"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imageomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-09 00:00:00.000000000 Z
11
+ date: 2022-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -53,6 +53,7 @@ files:
53
53
  - lib/generators/imageomatic/install/templates/application.opengraph.erb
54
54
  - lib/imageomatic.rb
55
55
  - lib/imageomatic/engine.rb
56
+ - lib/imageomatic/url_signature.rb
56
57
  - lib/imageomatic/version.rb
57
58
  - lib/tasks/imageomatic_tasks.rake
58
59
  homepage: https://www.imageomatic.com/