cloudimage 0.1.0 → 0.2.0

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: 38b6b4cf631917e41ac56722f43b942e77714815d52ac15a7080e56173d776e5
4
- data.tar.gz: 8b5d8d15e125b076908c6d9a9e36cffe13dce4c89b2b7586235ccbc0c4e8dd71
3
+ metadata.gz: abb64d67ac6a4a0d7e87cd0758c94497b1c31a96f4dcfc9a4d10d2b66e4460b6
4
+ data.tar.gz: f12f312eea0653ee858bcc0c124a842a574ee6e63b820832c93f275687d463e3
5
5
  SHA512:
6
- metadata.gz: 4405e0f5eacfd9417fc300b801cafac50a1a9e352c64bf7e611e401e66d6ac6cde6743c9a00db116118f2ae8eb2433cc5dba99fe695bc3705b0dd96911db4589
7
- data.tar.gz: 28126cfc5f7c63153a6ef57b0b1bad2bd93cd22d14b093f68fa340ab2a65d730d3d25f84b3d3bedf676cca92547f0bd6bf579f5d3b55807755f899e9e273f9aa
6
+ metadata.gz: ec3ede4d88539362085fe46726453aa9fca339bb875a2071c897d4797a093aef6caec2805e2927f363d0ea27f21ef319634513fc855e748b76366399840cb6aa
7
+ data.tar.gz: d292ff52e7d4219bdbf3a0668c22f9c26da414bc187246eeb97caf550c80762a54462f5752da08312f94233caa87c5a09c156519e94093e1e3d0ee833cf4093b
@@ -1,6 +1,17 @@
1
1
  ## master
2
2
 
3
- ## 0.1.0 (2020-08-09)
3
+ ## 0.2.0 (2020-06-28)
4
+
5
+ - URL signatures.
6
+ [#6](https://github.com/scaleflex/cloudimage-rb/pull/6) (@janklimo)
7
+ - Added the remaining API params so that they can be used as helpers.
8
+ [#7](https://github.com/scaleflex/cloudimage-rb/pull/7) (@janklimo)
9
+ - We don't run `rubocop` on `truffleruby` anymore.
10
+ It [is not officially supported](https://docs.rubocop.org/rubocop/compatibility.html)
11
+ and leads to [unexpected issues](https://github.com/scaleflex/cloudimage-rb/runs/815208955?check_suite_focus=true).
12
+ [#7](https://github.com/scaleflex/cloudimage-rb/pull/7) (@janklimo)
13
+
14
+ ## 0.1.0 (2020-06-09)
4
15
 
5
16
  - Introduce base models: `Cloudimage::Client`, and `Cloudimage::URI`. Generate
6
17
  URLs via `to_url` method. Add support for image resizing params.
data/README.md CHANGED
@@ -14,7 +14,9 @@ Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
14
14
  - [Chainable helpers](#chainable-helpers)
15
15
  - [Aliases](#aliases)
16
16
  - [Custom helpers](#custom-helpers)
17
+ - [Security](#security)
17
18
  - [Development](#development)
19
+ - [TODOs](#todos)
18
20
  - [Contributing](#contributing)
19
21
  - [License](#license)
20
22
  - [Code of Conduct](#code-of-conduct)
@@ -49,6 +51,15 @@ object:
49
51
  client = Cloudimage::Client.new(token: 'mysecrettoken')
50
52
  ```
51
53
 
54
+ Cloudimage client accepts the following options:
55
+
56
+ | Option | Required? | Additional info |
57
+ | ------------------ | --------- | --------------------------------------------------- |
58
+ | `token` | Yes | |
59
+ | `salt` | No | See [Security](#security). |
60
+ | `signature_length` | No | Integer value in the range `6..40`. Defaults to 18. |
61
+ | `api_version` | No | Defaults to the current stable version. |
62
+
52
63
  Calling `path` on the client object returns an instance of `Cloudimage::URI`.
53
64
  It accepts path to the image as a string and we we will use it to build
54
65
  Cloudimage URLs.
@@ -108,6 +119,20 @@ need to accept arguments and will be translated into `param=1` in the final URL.
108
119
  For a list of custom helpers available to you, please consult
109
120
  [`Cloudimage::CustomHelpers`](lib/cloudimage/custom_helpers.rb) module.
110
121
 
122
+ ### Security
123
+
124
+ If `salt` is defined, all URLs will be signed.
125
+
126
+ You can control the length of the generated signature by specifying `signature_length`
127
+ when initializing the client.
128
+
129
+ ```ruby
130
+ client = Cloudimage::Client.new(token: 'mysecrettoken', salt: 'mysecretsalt', signature_length: 10)
131
+ uri = client.path('/assets/image.png')
132
+ uri.w(200).h(400).to_url
133
+ # => "https://mysecrettoken.cloudimg.io/v7/assets/image.png?h=400&w=200&ci_sign=79cfbc458b"
134
+ ```
135
+
111
136
  ## Development
112
137
 
113
138
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -115,6 +140,13 @@ Then, run `bundle exec rake` to run the tests. You can also run
115
140
  `bin/console` for an interactive prompt that will allow you to
116
141
  experiment.
117
142
 
143
+ ### TODOs
144
+
145
+ - URL sealing
146
+ - Add support for custom CNAMEs
147
+ - `srcset` generation
148
+ - Purge cache API
149
+
118
150
  ## Contributing
119
151
 
120
152
  Bug reports and pull requests are welcome. This project is intended
@@ -6,30 +6,44 @@ module Cloudimage
6
6
  class InvalidConfig < StandardError; end
7
7
 
8
8
  class Client
9
- attr_reader :token
9
+ attr_reader :config
10
10
 
11
11
  API_VERSION = 'v7'
12
+ DEFAULT_SIGNATURE_LENGTH = 18
12
13
 
13
- def initialize(token: nil)
14
- @token = token
14
+ def initialize(**options)
15
+ @config = {}
16
+ @config[:token] = options[:token]
17
+ @config[:salt] = options[:salt]
18
+ @config[:signature_length] =
19
+ options[:signature_length] || DEFAULT_SIGNATURE_LENGTH
20
+ @config[:api_version] = API_VERSION
15
21
 
16
22
  ensure_valid_config
17
23
  end
18
24
 
19
25
  def path(path)
20
- URI.new(base_url_for(token), path)
26
+ URI.new(path, **config)
21
27
  end
22
28
 
23
29
  private
24
30
 
25
- def base_url_for(token)
26
- "https://#{token}.cloudimg.io/#{API_VERSION}"
31
+ def ensure_valid_config
32
+ ensure_valid_token
33
+ ensure_valid_signature_length
27
34
  end
28
35
 
29
- def ensure_valid_config
30
- return unless token.to_s.strip.empty?
36
+ def ensure_valid_token
37
+ return unless config[:token].nil?
31
38
 
32
39
  raise InvalidConfig, 'Please specify your Cloudimage customer token.'
33
40
  end
41
+
42
+ def ensure_valid_signature_length
43
+ return if config[:salt].nil?
44
+ return if (6..40).cover? config[:signature_length]
45
+
46
+ raise InvalidConfig, 'Signature length must be must be 6-40 characters.'
47
+ end
34
48
  end
35
49
  end
@@ -18,18 +18,45 @@ module Cloudimage
18
18
  bg_colourise
19
19
  bg_img_fit
20
20
  bg_opacity
21
+ blur
22
+ blur_faces
21
23
  br_px
24
+ bright
22
25
  ci_info
26
+ contrast
27
+ doc_page
28
+ f
29
+ force_format
23
30
  func
24
31
  gravity
32
+ gray
33
+ grey
25
34
  h
26
35
  height
36
+ optipress
27
37
  org_if_sml
38
+ p
39
+ pixelate
40
+ pixellate
41
+ process
42
+ q
28
43
  r
44
+ radius
29
45
  sharp
30
46
  tl_px
31
47
  trim
32
48
  w
49
+ wat
50
+ wat_color
51
+ wat_colour
52
+ wat_url
53
+ wat_font
54
+ wat_fontsize
55
+ wat_gravity
56
+ wat_opacity
57
+ wat_pad
58
+ wat_scale
59
+ wat_text
33
60
  width
34
61
  ].freeze
35
62
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'digest'
4
+
3
5
  require_relative 'params'
4
6
  require_relative 'custom_helpers'
5
7
 
@@ -8,12 +10,12 @@ module Cloudimage
8
10
  include Params
9
11
  include CustomHelpers
10
12
 
11
- attr_reader :uri, :params
13
+ attr_reader :uri, :params, :config
12
14
 
13
- def initialize(base_url, path)
14
- path = ensure_path_format(path)
15
- @uri = Addressable::URI.parse(base_url + path)
15
+ def initialize(path, **config)
16
+ @config = config
16
17
  @params = {}
18
+ @uri = build_uri_from(path)
17
19
  end
18
20
 
19
21
  PARAMS.each do |param|
@@ -32,16 +34,45 @@ module Cloudimage
32
34
  alias_method from, to
33
35
  end
34
36
 
35
- def to_url(extra_params = {})
36
- url_params = params.merge(extra_params)
37
- uri.query_values = url_params if url_params.any?
38
- uri.to_s
37
+ def to_url(**extra_params)
38
+ set_uri_params(**extra_params)
39
+ sign_url
39
40
  end
40
41
 
41
42
  private
42
43
 
43
- def ensure_path_format(path)
44
- path.start_with?('/') ? path : "/#{path}"
44
+ def base_url
45
+ "https://#{config[:token]}.cloudimg.io"
46
+ end
47
+
48
+ def base_url_with_api_version
49
+ "#{base_url}/#{config[:api_version]}"
50
+ end
51
+
52
+ def build_uri_from(path)
53
+ formatted_path = path.start_with?('/') ? path : "/#{path}"
54
+ Addressable::URI.parse(base_url_with_api_version + formatted_path)
55
+ end
56
+
57
+ def set_uri_params(**extra_params)
58
+ url_params = params.merge(**extra_params)
59
+ return unless url_params.any?
60
+
61
+ uri.query_values = url_params
62
+ end
63
+
64
+ def sign_url
65
+ url = uri.to_s
66
+
67
+ return url if config[:salt].nil?
68
+
69
+ url + "#{uri.query_values ? '&' : '?'}ci_sign=#{signature}"
70
+ end
71
+
72
+ def signature
73
+ path = uri.to_s.sub(base_url_with_api_version, '')
74
+ digest = Digest::SHA1.hexdigest(config[:salt] + path)
75
+ digest[0..(config[:signature_length] - 1)]
45
76
  end
46
77
  end
47
78
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudimage
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Klimo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2020-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -51,7 +51,7 @@ metadata:
51
51
  changelog_uri: https://github.com/scaleflex/cloudimage-rb/blob/master/CHANGELOG.md
52
52
  source_code_uri: https://github.com/scaleflex/cloudimage-rb
53
53
  documentation_uri: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.1.2
70
- signing_key:
69
+ rubygems_version: 3.1.4
70
+ signing_key:
71
71
  specification_version: 4
72
72
  summary: Official API wrapper for Cloudimage's API.
73
73
  test_files: []