camo 0.2.0 → 0.2.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: aba71bc194731f9fdf0518c0ae2aebd228c856263e928485678e00990cbf04ab
4
- data.tar.gz: 31b6017ef24aa772444090702572dd7b7dad32ea8de3a0849ca40dbfc66aafb3
3
+ metadata.gz: 7f9d615b8d94009e7ec746874527a8a56529d2c27d7d24af586e01adf0a8cab0
4
+ data.tar.gz: ba444423761f620a91d0a86821310ce7377e5b46fd376f5dd7629989462b88cf
5
5
  SHA512:
6
- metadata.gz: de569a318e30cf32a6623274a44a0b1fcc6274872afe55215c1d3049c6fcdc1a118efe76815be21f7c3141db325830e100139e801ca74a729ee9dcfe00adbeca
7
- data.tar.gz: 33f8bbdefb3ca81398435cc36e83067bdb0f5a82049fbab34885b465aef5a07fca6548d2c23dbca50c91f9648f0800ce1bce52d61894f234266905aca4cf0018
6
+ metadata.gz: 0440adf94048d1b3ec14c5b0b6f6546ac9adb0d97fd5e6b88458dc4a02c394f793931054f3c2a54e5b14f6b4c8c31194b973daae13a0fe4060378c9bf49ec443
7
+ data.tar.gz: e194661a571e4ca51871ebcd2229bb28dc26d982076f4eff07b565eba520d16d8cd1b1e83f65b588f6a65a4a76c3af8e99be0f41f2da36a3b888ed56e7ddf874
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.1 (2022-10-09)
2
+
3
+ - Added `key` option to `camo` method
4
+
1
5
  ## 0.2.0 (2022-09-05)
2
6
 
3
7
  - Dropped support for Ruby < 2.7
@@ -0,0 +1,16 @@
1
+ module Camo
2
+ module Helper
3
+ def camo(image_url, key: nil)
4
+ key ||= Camo.key
5
+ host = Camo.host
6
+
7
+ raise "No CAMO_KEY" unless key
8
+ raise "No CAMO_HOST" unless host
9
+
10
+ # TODO support base64 encoding
11
+ hexdigest = OpenSSL::HMAC.hexdigest("sha1", key, image_url)
12
+ encoded_image_url = image_url.unpack1("H*")
13
+ "#{host}/#{hexdigest}/#{encoded_image_url}"
14
+ end
15
+ end
16
+ end
data/lib/camo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Camo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/camo.rb CHANGED
@@ -2,28 +2,36 @@
2
2
  require "openssl"
3
3
 
4
4
  # modules
5
+ require "camo/helper"
5
6
  require "camo/version"
6
7
 
7
8
  module Camo
8
- def camo(image_url)
9
- raise "No CAMO_KEY" unless ENV["CAMO_KEY"]
10
- raise "No CAMO_HOST" unless ENV["CAMO_HOST"]
11
- hexdigest = OpenSSL::HMAC.hexdigest("sha1", ENV["CAMO_KEY"], image_url)
12
- encoded_image_url = image_url.unpack1("H*")
13
- "#{ENV["CAMO_HOST"]}/#{hexdigest}/#{encoded_image_url}"
9
+ class << self
10
+ attr_writer :host, :key
11
+
12
+ def host
13
+ @host ||= ENV["CAMO_HOST"]
14
+ end
15
+
16
+ def key
17
+ @key ||= ENV["CAMO_KEY"]
18
+ end
14
19
  end
20
+
21
+ # TODO remove in 0.3.0
22
+ include Helper
15
23
  end
16
24
 
17
25
  if defined?(ActiveSupport)
18
26
  ActiveSupport.on_load(:action_view) do
19
- include Camo
27
+ include Camo::Helper
20
28
  end
21
29
 
22
30
  ActiveSupport.on_load(:action_controller) do
23
- include Camo
31
+ include Camo::Helper
24
32
  end
25
33
  end
26
34
 
27
35
  if defined?(Sinatra)
28
- Sinatra::Base.helpers Camo
36
+ Sinatra::Base.helpers Camo::Helper
29
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -20,6 +20,7 @@ files:
20
20
  - LICENSE.txt
21
21
  - README.md
22
22
  - lib/camo.rb
23
+ - lib/camo/helper.rb
23
24
  - lib/camo/version.rb
24
25
  homepage: https://github.com/ankane/camo-ruby
25
26
  licenses: