cloudimage 0.5.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +62 -23
- data/lib/cloudimage/client.rb +2 -0
- data/lib/cloudimage/srcset.rb +31 -0
- data/lib/cloudimage/uri.rb +13 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c02d5fa30289aa70eb6b0d94e13f31130e5c1918ffb18d45197bb0b62cda26de
|
4
|
+
data.tar.gz: ce5da501f8200577f7c9003dba581b59f88628c99a03d54fa662ed0f336737fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f698aefba14fee30249e29e431cf53d1e25440c97c08731ac4c050ba0bc58a95eeeac93143301fdd7cc31d7e96a4cdedac653aa832b61adf2f8c2a7681748d52
|
7
|
+
data.tar.gz: 3a58f037be0329dfbdfd4c1b0d0a71848caaf7d9c42fc1e9425d5f4c43015b81ee60cec29ef84cbf3318a6c195af851d82ab042d12166e7e98ae16bacff5bf2b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.5.0](https://github.com/scaleflex/cloudimage-rb/tree/v0.5.0) (2020-08-02)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/scaleflex/cloudimage-rb/compare/v0.4.0...v0.5.0)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Invalidation [\#24](https://github.com/scaleflex/cloudimage-rb/pull/24) ([janklimo](https://github.com/janklimo))
|
10
|
+
- Add support for custom CNAMEs [\#21](https://github.com/scaleflex/cloudimage-rb/pull/21) ([janklimo](https://github.com/janklimo))
|
11
|
+
|
3
12
|
## [v0.4.0](https://github.com/scaleflex/cloudimage-rb/tree/v0.4.0) (2020-07-19)
|
4
13
|
|
5
14
|
[Full Changelog](https://github.com/scaleflex/cloudimage-rb/compare/v0.3.0...v0.4.0)
|
@@ -15,7 +24,6 @@
|
|
15
24
|
**Implemented enhancements:**
|
16
25
|
|
17
26
|
- Introduce URL sealing [\#10](https://github.com/scaleflex/cloudimage-rb/pull/10) ([janklimo](https://github.com/janklimo))
|
18
|
-
- Add support for image resizing [\#2](https://github.com/scaleflex/cloudimage-rb/pull/2) ([janklimo](https://github.com/janklimo))
|
19
27
|
|
20
28
|
**Merged pull requests:**
|
21
29
|
|
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/cloudimage) 
|
4
4
|
|
5
|
-
`cloudimage` is the official Ruby API wrapper for
|
6
|
-
[Cloudimage's API](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction).
|
5
|
+
`cloudimage` is the official Ruby API wrapper for [Cloudimage's API][docs].
|
7
6
|
|
8
7
|
Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
|
9
8
|
|
@@ -15,7 +14,9 @@ Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
|
|
15
14
|
- [Method aliases](#method-aliases)
|
16
15
|
- [Custom helpers](#custom-helpers)
|
17
16
|
- [URL aliases](#url-aliases)
|
17
|
+
- [`srcset` generation](#srcset-generation)
|
18
18
|
- [CNAME](#cname)
|
19
|
+
- [Optional API version](#optional-api-version)
|
19
20
|
- [Security](#security)
|
20
21
|
- [URL signature](#url-signature)
|
21
22
|
- [URL sealing](#url-sealing)
|
@@ -57,15 +58,16 @@ client = Cloudimage::Client.new(token: 'mysecrettoken')
|
|
57
58
|
|
58
59
|
Cloudimage client accepts the following options:
|
59
60
|
|
60
|
-
| Option
|
61
|
-
|
|
62
|
-
| `token`
|
63
|
-
| `cname`
|
64
|
-
| `salt`
|
65
|
-
| `signature_length`
|
66
|
-
| `sign_urls`
|
67
|
-
| `aliases`
|
68
|
-
| `api_key`
|
61
|
+
| Option | Type | Additional info |
|
62
|
+
| --------------------- | ------- | ------------------------------------------------------------------------------ |
|
63
|
+
| `token` | string | Required if `cname` is missing. |
|
64
|
+
| `cname` | string | Required if `token` is missing. See [CNAME](#cname). |
|
65
|
+
| `salt` | string | Optional. See [Security](#security). |
|
66
|
+
| `signature_length` | integer | Optional. Integer value in the range `6..40`. Defaults to 18. |
|
67
|
+
| `sign_urls` | boolean | Optional. Defaults to `true`. See [Security](#security). |
|
68
|
+
| `aliases` | hash | Optional. See [URL aliases](#url-aliases). |
|
69
|
+
| `api_key` | string | Optional. See [Invalidation API](#invalidation-api). |
|
70
|
+
| `include_api_version` | boolean | Optional. Defaults to true. See [Optional API version](#optional-api-version). |
|
69
71
|
|
70
72
|
Calling `path` on the client object returns an instance of `Cloudimage::URI`.
|
71
73
|
It accepts path to the image as a string and we we will use it to build
|
@@ -128,9 +130,8 @@ For a list of custom helpers available to you, please consult
|
|
128
130
|
|
129
131
|
### URL aliases
|
130
132
|
|
131
|
-
Specify [aliases]
|
132
|
-
|
133
|
-
maps strings to be replaced with values to be used instead.
|
133
|
+
Specify [aliases][aliases] to automatically replace parts of path with defined values.
|
134
|
+
Aliases is a hash which maps strings to be replaced with values to be used instead.
|
134
135
|
|
135
136
|
```ruby
|
136
137
|
my_alias = 'https://store.s3-us-west-2.amazonaws.com/uploads'
|
@@ -139,8 +140,7 @@ client.path('https://store.s3-us-west-2.amazonaws.com/uploads/image.jpg').to_url
|
|
139
140
|
# => "https://token.cloudimg.io/v7/_uploads_/image.jpg"
|
140
141
|
```
|
141
142
|
|
142
|
-
[URL prefix]
|
143
|
-
is just another form of URL alias. Simply make the target value an empty string:
|
143
|
+
[URL prefix][url-prefix] is just another form of URL alias. Simply make the target value an empty string:
|
144
144
|
|
145
145
|
```ruby
|
146
146
|
prefix = 'https://store.s3-us-west-2.amazonaws.com/uploads/'
|
@@ -149,6 +149,29 @@ client.path('https://store.s3-us-west-2.amazonaws.com/uploads/image.jpg').to_url
|
|
149
149
|
# => "https://token.cloudimg.io/v7/image.jpg"
|
150
150
|
```
|
151
151
|
|
152
|
+
You don't need to specify an alias if the input to `path` is a URL that
|
153
|
+
already matches the base of the generated URL:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
client = Cloudimage::Client.new(token: 'token')
|
157
|
+
client.path('https://token.cloudimg.io/v7/image.jpg').to_url(w: 200)
|
158
|
+
=> "https://token.cloudimg.io/v7/image.jpg?w=200"
|
159
|
+
```
|
160
|
+
|
161
|
+
### `srcset` generation
|
162
|
+
|
163
|
+
Use the provided `to_srcset` method which also accepts any additional params to
|
164
|
+
be applied to the `srcset` URLs:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
client = Cloudimage::Client.new(token: 'token')
|
168
|
+
client.path('/assets/image.jpg').to_srcset(blur: 5)
|
169
|
+
# => "https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=100 100w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=170 170w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=280 280w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=470 470w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=780 780w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=1300 1300w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=2170 2170w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=3620 3620w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=5760 5760w"
|
170
|
+
```
|
171
|
+
|
172
|
+
A growth factor is applied to exponentially distribute widths between 100 and 5760 pixels.
|
173
|
+
See [`Cloudimage::Srcset`](/lib/cloudimage/srcset.rb) for implementation details.
|
174
|
+
|
152
175
|
### CNAME
|
153
176
|
|
154
177
|
If you have a custom CNAME configured for your account, you can
|
@@ -160,6 +183,17 @@ client.path('/assets/image.jpg').to_url
|
|
160
183
|
# => 'https://img.klimo.io/v7/assets/image.jpg'
|
161
184
|
```
|
162
185
|
|
186
|
+
### Optional API version
|
187
|
+
|
188
|
+
If your account is configured to work without the API version component in the URL,
|
189
|
+
you can configure client not to include it in the generated URL:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
client = Cloudimage::Client.new(cname: 'img.klimo.io', include_api_version: false)
|
193
|
+
client.path('/assets/image.jpg').to_url
|
194
|
+
# => "https://img.klimo.io/assets/image.jpg"
|
195
|
+
```
|
196
|
+
|
163
197
|
### Security
|
164
198
|
|
165
199
|
#### URL signature
|
@@ -182,8 +216,7 @@ Whereas URL signatures let you protect your URL from any kind of
|
|
182
216
|
tampering, URL sealing protects the params you specify while making
|
183
217
|
it possible to append additional params on the fly.
|
184
218
|
|
185
|
-
This is useful when working with Cloudimage's
|
186
|
-
[responsive frontend libraries](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/responsive-images).
|
219
|
+
This is useful when working with Cloudimage's [responsive frontend libraries][responsive-images].
|
187
220
|
A common use case would be sealing your watermark but letting the
|
188
221
|
React client request the best possible width.
|
189
222
|
|
@@ -236,8 +269,7 @@ client.invalidate_urls('/v7/image.jpg?w=200', '/v7/image.jpg?h=300')
|
|
236
269
|
client.invalidate_all
|
237
270
|
```
|
238
271
|
|
239
|
-
Consult the [API docs]
|
240
|
-
for further details.
|
272
|
+
Consult the [invalidation API docs][invalidation-docs] for further details.
|
241
273
|
|
242
274
|
## Development
|
243
275
|
|
@@ -250,8 +282,7 @@ experiment.
|
|
250
282
|
|
251
283
|
Bug reports and pull requests are welcome. This project is intended
|
252
284
|
to be a safe, welcoming space for collaboration, and contributors
|
253
|
-
are expected to adhere to the
|
254
|
-
[code of conduct](https://github.com/scaleflex/cloudimage-rb/blob/master/CODE_OF_CONDUCT.md).
|
285
|
+
are expected to adhere to the [code of conduct][code-of-conduct].
|
255
286
|
|
256
287
|
## License
|
257
288
|
|
@@ -261,7 +292,15 @@ are expected to adhere to the
|
|
261
292
|
|
262
293
|
Among others, `cloudimage` is used to power the following apps:
|
263
294
|
|
264
|
-
- [Robin PRO]
|
295
|
+
- [Robin PRO][robin-pro] - Fast, beautiful, mobile-friendly image galleries for Shopify stores.
|
265
296
|
|
266
297
|
Using this gem in your app? Let us know in [this issue](https://github.com/scaleflex/cloudimage-rb/issues/8)
|
267
298
|
so that we can feature it.
|
299
|
+
|
300
|
+
[aliases]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/domains-urls/aliases
|
301
|
+
[code-of-conduct]: https://github.com/scaleflex/cloudimage-rb/blob/master/CODE_OF_CONDUCT.md
|
302
|
+
[docs]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction
|
303
|
+
[invalidation-docs]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/caching-acceleration/invalidation-api
|
304
|
+
[responsive-images]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/responsive-images
|
305
|
+
[robin-pro]: https://apps.shopify.com/robin-pro-image-gallery
|
306
|
+
[url-prefix]: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/domains-urls/origin-url-prefix
|
data/lib/cloudimage/client.rb
CHANGED
@@ -30,6 +30,8 @@ module Cloudimage
|
|
30
30
|
config[:signature_length] =
|
31
31
|
options[:signature_length] || DEFAULT_SIGNATURE_LENGTH
|
32
32
|
config[:api_version] = API_VERSION
|
33
|
+
config[:include_api_version] =
|
34
|
+
options[:include_api_version].nil? ? true : false
|
33
35
|
config[:sign_urls] = options[:sign_urls].nil? ? true : false
|
34
36
|
config[:aliases] = options[:aliases] || {}
|
35
37
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cloudimage
|
4
|
+
module Srcset
|
5
|
+
# 5760 is 3x 1920 (the largest common screen width):
|
6
|
+
# https://gs.statcounter.com/screen-resolution-stats
|
7
|
+
SRCSET_RANGE = (100..5_760).freeze
|
8
|
+
SRCSET_GROWTH_FACTOR = 1.67
|
9
|
+
|
10
|
+
def to_srcset(**extra_params)
|
11
|
+
srcset_widths
|
12
|
+
.map { |width| "#{to_url(**extra_params, w: width)} #{width}w" }
|
13
|
+
.join(', ')
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def srcset_widths
|
19
|
+
current = SRCSET_RANGE.begin
|
20
|
+
|
21
|
+
[].tap do |widths|
|
22
|
+
loop do
|
23
|
+
widths << current
|
24
|
+
current = (current * SRCSET_GROWTH_FACTOR).round(-1)
|
25
|
+
|
26
|
+
break if current >= SRCSET_RANGE.end && widths << SRCSET_RANGE.end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/cloudimage/uri.rb
CHANGED
@@ -5,6 +5,7 @@ require 'set'
|
|
5
5
|
require_relative 'params'
|
6
6
|
require_relative 'custom_helpers'
|
7
7
|
require_relative 'security'
|
8
|
+
require_relative 'srcset'
|
8
9
|
require_relative 'refinements'
|
9
10
|
|
10
11
|
module Cloudimage
|
@@ -13,6 +14,7 @@ module Cloudimage
|
|
13
14
|
|
14
15
|
include Params
|
15
16
|
include CustomHelpers
|
17
|
+
include Srcset
|
16
18
|
|
17
19
|
attr_reader :path, :uri, :params, :config, :sealed_params
|
18
20
|
|
@@ -61,21 +63,29 @@ module Cloudimage
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def apply_aliases(path)
|
64
|
-
|
66
|
+
config[:aliases][default_alias] = ''
|
65
67
|
|
66
68
|
path.dup.tap do |input|
|
67
69
|
config[:aliases].each do |source, target|
|
68
|
-
input.
|
70
|
+
input.sub!(source, target)
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
75
|
+
def default_alias
|
76
|
+
config[:include_api_version] ? "#{site}#{api_version}/" : "#{site}/"
|
77
|
+
end
|
78
|
+
|
73
79
|
def request_uri
|
74
80
|
uri.request_uri.delete_prefix(api_version)
|
75
81
|
end
|
76
82
|
|
77
83
|
def build_uri
|
78
|
-
|
84
|
+
if config[:include_api_version]
|
85
|
+
Addressable::URI.parse(site + api_version + path)
|
86
|
+
else
|
87
|
+
Addressable::URI.parse(site + path)
|
88
|
+
end
|
79
89
|
end
|
80
90
|
|
81
91
|
def set_uri_params(**extra_params)
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Klimo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/cloudimage/params.rb
|
73
73
|
- lib/cloudimage/refinements.rb
|
74
74
|
- lib/cloudimage/security.rb
|
75
|
+
- lib/cloudimage/srcset.rb
|
75
76
|
- lib/cloudimage/uri.rb
|
76
77
|
homepage: https://github.com/scaleflex/cloudimage-rb
|
77
78
|
licenses:
|