imglab 0.1.1 → 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: 87c1e0449e9f2b7e000fda519d3413e205cdfab3d9c87c85bfd2edcc2f5e9467
4
- data.tar.gz: 173c5436f148213ac172bf83e3a65a013d6d169264d9252419c3f6e5bb4c0216
3
+ metadata.gz: cf939223729128b42634757899edf1587158d8ca042246f53eb87a440fca5251
4
+ data.tar.gz: 7635dd0f8eab66ab587b95e48665660d836a7a0d598601098b83f884f18bdcdd
5
5
  SHA512:
6
- metadata.gz: 39276c9dc2443af3d62b81f20b6313ff0c043300021c21ef9773244543df9967b2fb8afd625404f46528509026d4d18fe17113fc9042e9d06df7eec1a4aa750b
7
- data.tar.gz: ecc2f549086dbd82f72820d59787192699abfb0c1c7d35c356a58ec1c01452d87e9a9541cc46cf6efa955b42d7417b0de206f164231f5c0f2d8c2ea775be5053
6
+ metadata.gz: 22943677cf74e75e8a77b52f0ac83c5eed5df72c85edb54180eba8c262881f0d264cc60ed40b015dec1b6aeecd7deb9d65d86493162dc6068d3ad8a546a321fa
7
+ data.tar.gz: 367a286bd40425c71594cf151a3d9a72d9f1a51291104b123bc778ddd342ed61f1d8572b1ef14c7e827932638051f236b9c99faacee029719e18c1017037f5ea
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem "imglab", "~> 0.1"
10
+ gem "imglab", "~> 0.2"
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -24,7 +24,7 @@ $ gem install imglab
24
24
 
25
25
  ## Ruby compatibility
26
26
 
27
- `imglab` has been successfully tested on the following Ruby versions: `3.0`, `2.7`, `2.6`, `2.5`, `2.4`, `2.3`, `2.2`, `2.1` and `2.0`.
27
+ `imglab` has been successfully tested on the following Ruby versions: `3.1`, `3.0`, `2.7`, `2.6`, `2.5`, `2.4`, `2.3`, `2.2`, `2.1` and `2.0`.
28
28
 
29
29
  ## Generating URLs
30
30
 
@@ -34,17 +34,17 @@ The easiest way to generate a URL is to specify the `source_name`, `path` and re
34
34
 
35
35
  ```ruby
36
36
  Imglab.url("assets", "image.jpeg", width: 500, height: 600)
37
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600"
37
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600"
38
38
 
39
39
  Imglab.url("avatars", "user-01.jpeg", width: 300, height: 300, mode: :crop, crop: :face, format: :webp)
40
- "https://cdn.imglab.io/avatars/user-01.jpeg?width=300&height=300&mode=crop&crop=face&format=webp"
40
+ "https://avatars.imglab-cdn.net/user-01.jpeg?width=300&height=300&mode=crop&crop=face&format=webp"
41
41
  ```
42
42
 
43
43
  If some specific settings are required for the source you can use an instance of `Imglab::Source` class instead of a `string` source name:
44
44
 
45
45
  ```ruby
46
46
  Imglab.url(Imglab::Source.new("assets"), "image.jpeg", width: 500, height: 600)
47
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600"
47
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600"
48
48
  ```
49
49
 
50
50
  ### Using secure image sources
@@ -55,7 +55,7 @@ For sources that require signed URLs you can specify `secure_key` and `secure_sa
55
55
  source = Imglab::Source.new("assets", secure_key: "assets-secure-key", secure_salt: "assets-secure-salt")
56
56
 
57
57
  Imglab.url(source, "image.jpeg", width: 500, height: 600)
58
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&signature=generated-signature"
58
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&signature=generated-signature"
59
59
  ```
60
60
 
61
61
  `signature` query parameter will be automatically generated and attached to the returned URL.
@@ -68,7 +68,7 @@ In the case that HTTP schema is required instead of HTTPS you can set `https` at
68
68
 
69
69
  ```ruby
70
70
  Imglab.url(Imglab::Source.new("assets", https: false), "image.jpeg", width: 500, height: 600)
71
- "http://cdn.imglab.io/assets/image.jpeg?width=500&height=600"
71
+ "http://assets.imglab-cdn.net/image.jpeg?width=500&height=600"
72
72
  ```
73
73
 
74
74
  > Note: HTTPS is the default and recommended way to generate URLs with imglab.
@@ -79,21 +79,21 @@ Any parameter from the imglab API can be used to generate URLs with `Imglab.url`
79
79
 
80
80
  ```ruby
81
81
  Imglab.url("assets", "image.jpeg", trim: "color", trim_color: "black")
82
- "https://cdn.imglab.io/assets/image.jpeg?trim=color&trim-color=black"
82
+ "https://assets.imglab-cdn.net/image.jpeg?trim=color&trim-color=black"
83
83
  ```
84
84
 
85
85
  It is possible to use strings too:
86
86
 
87
87
  ```ruby
88
88
  Imglab.url("assets", "image.jpeg", "trim" => "color", "trim-color" => "black")
89
- "https://cdn.imglab.io/assets/image.jpeg?trim=color&trim-color=black"
89
+ "https://assets.imglab-cdn.net/image.jpeg?trim=color&trim-color=black"
90
90
  ```
91
91
 
92
92
  And quoted symbols for Ruby version >= 2.2:
93
93
 
94
94
  ```ruby
95
95
  Imglab.url("assets", "image.jpeg", trim: "color", "trim-color": "black")
96
- "https://cdn.imglab.io/assets/image.jpeg?trim=color&trim-color=black"
96
+ "https://assets.imglab-cdn.net/image.jpeg?trim=color&trim-color=black"
97
97
  ```
98
98
 
99
99
  ### Specifying color parameters
@@ -103,19 +103,19 @@ Some imglab parameters can receive a color as value. It is possible to specify t
103
103
  ```ruby
104
104
  # Specifying a RGB color as string
105
105
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: :contain, background_color: "255,0,0")
106
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0"
106
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0"
107
107
 
108
108
  # Specifying a RGBA color as string
109
109
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: :contain, background_color: "255,0,0,128")
110
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0%2C128"
110
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0%2C128"
111
111
 
112
112
  # Specifying a named color as string
113
113
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: :contain, background_color: "red")
114
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=red"
114
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=red"
115
115
 
116
116
  # Specifying a hexadecimal color as string
117
117
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: :contain, background_color: "F00")
118
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=F00"
118
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=F00"
119
119
  ```
120
120
 
121
121
  You can additionally use `Imglab::Color` helpers to specify these color values:
@@ -126,15 +126,15 @@ include Imglab::Color
126
126
 
127
127
  # Using color helper for a RGB color
128
128
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: "contain", background_color: color(255, 0, 0))
129
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0"
129
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0"
130
130
 
131
131
  # Using color helper for a RGBA color
132
132
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: "contain", background_color: color(255, 0, 0, 128))
133
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0%2C128"
133
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=255%2C0%2C0%2C128"
134
134
 
135
135
  # Using color helper for a named color
136
136
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, mode: "contain", background_color: color("red"))
137
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&mode=contain&background-color=red"
137
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&mode=contain&background-color=red"
138
138
  ```
139
139
 
140
140
  > Note: specify hexadecimal color values using `Imglab::Color` helpers is not allowed. You can use strings instead.
@@ -146,15 +146,15 @@ Some imglab parameters can receive a position as value. It is possible to specif
146
146
  ```ruby
147
147
  # Specifying a horizontal and vertical position as string
148
148
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: "left,top")
149
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left%2Ctop"
149
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=left%2Ctop"
150
150
 
151
151
  # Specifying a vertical and horizontal position as string
152
152
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: "top,left")
153
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=top%2Cleft"
153
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=top%2Cleft"
154
154
 
155
155
  # Specifying a position as string
156
156
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: "left")
157
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left"
157
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=left"
158
158
  ```
159
159
 
160
160
  You can additionally use `Imglab::Position` helpers to specify these position values:
@@ -165,15 +165,15 @@ include Imglab::Position
165
165
 
166
166
  # Using position helper for a horizontal and vertical position
167
167
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("left", "top"))
168
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left%2Ctop"
168
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=left%2Ctop"
169
169
 
170
170
  # Using position helper for a vertical and horizontal position
171
171
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("top", "left"))
172
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=top%2Cleft"
172
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=top%2Cleft"
173
173
 
174
174
  # Using position helper for a position
175
175
  Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("left"))
176
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left"
176
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=500&mode=crop&crop=left"
177
177
  ```
178
178
 
179
179
  ### Specifying URL parameters
@@ -182,14 +182,14 @@ Some imglab parameters can receive URLs as values. It is possible to specify the
182
182
 
183
183
  ```ruby
184
184
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, watermark: "logo.svg")
185
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&watermark=logo.svg"
185
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&watermark=logo.svg"
186
186
  ```
187
187
 
188
188
  And even use parameters if required:
189
189
 
190
190
  ```ruby
191
191
  Imglab.url("assets", "image.jpeg", width: 500, height: 600, watermark: "logo.svg?width=100&format=png")
192
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&watermark=logo.svg%3Fwidth%3D100%26format%3Dpng"
192
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&watermark=logo.svg%3Fwidth%3D100%26format%3Dpng"
193
193
  ```
194
194
 
195
195
  Additionally you can use nested `Imglab.url` calls to specify these URL values:
@@ -202,7 +202,7 @@ Imglab.url(
202
202
  height: 600,
203
203
  watermark: Imglab.url("assets", "logo.svg", width: 100, format: "png")
204
204
  )
205
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&watermark=https%3A%2F%2Fcdn.imglab.io%2Fassets%2Flogo.svg%3Fwidth%3D100%26format%3Dpng"
205
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&watermark=https%3A%2F%2Fassets.imglab-cdn.net%2Flogo.svg%3Fwidth%3D100%26format%3Dpng"
206
206
  ```
207
207
 
208
208
  If the resource is located in a different source we can specify it using `Imglab.url`:
@@ -215,7 +215,7 @@ Imglab.url(
215
215
  height: 600,
216
216
  watermark: Imglab.url("marketing", "logo.svg", width: 100, format: "png")
217
217
  )
218
- "https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&watermark=https%3A%2F%2Fcdn.imglab.io%2Fmarketing%2Flogo.svg%3Fwidth%3D100%26format%3Dpng"
218
+ "https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&watermark=https%3A%2F%2Fmarketing.imglab-cdn.net%2Flogo.svg%3Fwidth%3D100%26format%3Dpng"
219
219
  ```
220
220
 
221
221
  Using secure sources for URLs parameter values is possible too:
@@ -239,50 +239,50 @@ Imglab.url(
239
239
  For on-premises imglab server is possible to define custom sources pointing to your server location.
240
240
 
241
241
  * `:https` - a `boolean` value specifying if the source should use https or not (default: `true`)
242
- * `:host` - a `string` specifying the host where the imglab server is located. (default: `cdn.imglab.io`)
242
+ * `:host` - a `string` specifying the host where the imglab server is located. (default: `imglab-cdn.net`)
243
243
  * `:port` - a `integer` specifying a port where the imglab server is located.
244
- * `:subdomains` - a `boolean` value specifying if the source should be specified using subdomains instead of using the path. (default: `false`)
244
+ * `:subdomains` - a `boolean` value specifying if the source should be specified using subdomains instead of using the path. (default: `true`)
245
245
 
246
- If we have our on-premises imglab server at `http://imglab.mycompany.com:8080` with a source named `web-images` we can use the following source settings to access a `logo.png` image:
246
+ If we have our on-premises imglab server at `http://my-company.com:8080` with a source named `images` we can use the following source settings to access a `logo.png` image:
247
247
 
248
248
  ```ruby
249
- source = Imglab::Source.new("web-images", https: false, host: "imglab.mycompany.com", port: 8080)
249
+ source = Imglab::Source.new("images", https: false, host: "my-company.com", port: 8080)
250
250
 
251
251
  Imglab.url(source, "logo.png", width: 300, height: 300, format: "png")
252
- "http://imglab.mycompany.com:8080/web-images/logo.png?width=300&height=300&format=png"
252
+ "http://images.my-company.com:8080/logo.png?width=300&height=300&format=png"
253
253
  ```
254
254
 
255
255
  It is possible to use secure sources too:
256
256
 
257
257
  ```ruby
258
258
  source = Imglab::Source.new(
259
- "web-images",
259
+ "images",
260
260
  https: false,
261
- host: "imglab.mycompany.com",
261
+ host: "my-company.com",
262
262
  port: 8080,
263
- secure_key: "web-images-secure-key",
264
- secure_salt: "web-images-secure-salt"
263
+ secure_key: "images-secure-key",
264
+ secure_salt: "images-secure-salt"
265
265
  )
266
266
 
267
267
  Imglab.url(source, "logo.png", width: 300, height: 300, format: "png")
268
- "http://imglab.mycompany.com:8080/web-images/logo.png?width=300&height=300&format=png&signature=generated-signature"
268
+ "http://images.my-company.com:8080/logo.png?width=300&height=300&format=png&signature=generated-signature"
269
269
  ```
270
270
 
271
- ### Using sudomains sources
271
+ ### Using sources with disabled subdomains
272
272
 
273
- In the case that your on-premises imglab server is configured to use source names as subdomains you can set `subdomains` attribute to `true` to generate URLs using subdomains:
273
+ In the case that your on-premises imglab server is configured to use source names as paths instead of subdomains you can set `subdomains` attribute to `false`:
274
274
 
275
275
  ```ruby
276
276
  source = Imglab::Source.new(
277
- "web-images",
277
+ "images",
278
278
  https: false,
279
- host: "imglab.mycompany.com",
279
+ host: "my-company.com",
280
280
  port: 8080,
281
- subdomains: true
281
+ subdomains: false
282
282
  )
283
283
 
284
- Imglab.url(source, "marketing/logo.png", width: 300, height: 300, format: "png")
285
- "http://web-images.imglab.mycompany.com:8080/marketing/logo.png?width=300&height=300&format=png"
284
+ Imglab.url(source, "logo.png", width: 300, height: 300, format: "png")
285
+ "http://my-company.com:8080/images/logo.png?width=300&height=300&format=png"
286
286
  ```
287
287
 
288
288
  ## License
data/lib/imglab/source.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Imglab::Source
2
2
  DEFAULT_HTTPS = true
3
- DEFAULT_HOST = "cdn.imglab.io"
4
- DEFAULT_SUBDOMAINS = false
3
+ DEFAULT_HOST = "imglab-cdn.net"
4
+ DEFAULT_SUBDOMAINS = true
5
5
 
6
6
  attr_reader :name, :https, :port, :secure_key, :secure_salt, :subdomains
7
7
 
@@ -13,7 +13,7 @@ class Imglab::Source
13
13
  # @param port [Integer] the port where the imglab server is located, only for imglab on-premises.
14
14
  # @param secure_key [String] the source secure key.
15
15
  # @param secure_salt [String] the source secure salt.
16
- # @param subdomains [Boolean] specify if the source should use subdomains to build the host name, only for imglab on-premises.
16
+ # @param subdomains [Boolean] specify if the source should use subdomains instead of paths to build the host name, only for imglab on-premises.
17
17
  # @return [Imglab::Source] with the specified options.
18
18
  def initialize(name, host: DEFAULT_HOST, https: DEFAULT_HTTPS, port: nil, secure_key: nil, secure_salt: nil, subdomains: DEFAULT_SUBDOMAINS)
19
19
  @name = name
@@ -50,7 +50,7 @@ class Imglab::Source
50
50
  # Returns if the source is secure or not.
51
51
  #
52
52
  # @return [Boolean]
53
- def secure?
53
+ def is_secure?
54
54
  @secure_key && @secure_salt
55
55
  end
56
56
 
@@ -1,3 +1,3 @@
1
1
  module Imglab
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/imglab.rb CHANGED
@@ -17,9 +17,9 @@ module Imglab
17
17
  # @raise [ArgumentError] when the source name or source parameter has a not expected type.
18
18
  #
19
19
  # @example Creating a URL specifying source name as string
20
- # Imglab.url("assets", "example.jpeg", width: 500, height: 600) #=> "https://cdn.imglab.io/assets/example.jpeg?width=500&height=600"
20
+ # Imglab.url("assets", "example.jpeg", width: 500, height: 600) #=> "https://assets.imglab-cdn.net/example.jpeg?width=500&height=600"
21
21
  # @example Creating a URL specifying a Imglab::Source
22
- # Imglab.url(Imglab::Source.new("assets"), "example.jpeg", width: 500, height: 600) #=> "https://cdn.imglab.io/assets/example.jpeg?width=500&height=600"
22
+ # Imglab.url(Imglab::Source.new("assets"), "example.jpeg", width: 500, height: 600) #=> "https://assets.imglab-cdn.net/example.jpeg?width=500&height=600"
23
23
  def self.url(source_name_or_source, path, params = {})
24
24
  case source_name_or_source
25
25
  when String
@@ -67,7 +67,7 @@ module Imglab
67
67
  def self.encode_params(source, path, params)
68
68
  return encode_empty_params(source, path) if params.empty?
69
69
 
70
- if source.secure?
70
+ if source.is_secure?
71
71
  signature = Signature.generate(source, path, URI.encode_www_form(params))
72
72
 
73
73
  URI.encode_www_form(params.merge(signature: signature))
@@ -77,7 +77,7 @@ module Imglab
77
77
  end
78
78
 
79
79
  def self.encode_empty_params(source, path)
80
- if source.secure?
80
+ if source.is_secure?
81
81
  signature = Signature.generate(source, path)
82
82
 
83
83
  URI.encode_www_form(signature: signature)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imglab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - imglab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Official Ruby library to integrate with imglab services.
14
14
  email:
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.1.6
57
+ rubygems_version: 3.2.33
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Official imglab Ruby library.