imgix 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -25
- data/lib/imgix.rb +0 -1
- data/lib/imgix/client.rb +10 -45
- data/lib/imgix/version.rb +1 -1
- data/test/units/domains_test.rb +3 -75
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ecfad08f5fb987982e65a9e4c22a7427f08be4
|
4
|
+
data.tar.gz: 23579307f97e575b2f30c065360b1244795e1081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '098a9a3ace9b4c06d8466ceb3ec4a3dc73ef64ee004d6d9d62082d200a0c19e34ad4b066eb418b36f7731213c30f1b172834e4b7a4deddc3326839ab1f12e1ae'
|
7
|
+
data.tar.gz: e1cd1ae2bb0eaeb1a6ddf330e53fe844d60cbc84133c102ba8f57774e3d6fe823f0eb820426af8adabacaa20b1cb9e1a77fb64cefdeb07c01e35ad649110b088
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [3.0.0](https://github.com/imgix/imgix-rb/compare/2.1.0...3.0.0) - June 7, 2019
|
7
|
+
|
8
|
+
* fix: remove deprecated domain sharding functionality ([#46](https://github.com/imgix/imgix-rb/pull/46))
|
9
|
+
|
6
10
|
## [2.1.0](https://github.com/imgix/imgix-rb/compare/2.0.0...2.1.0) - May 7, 2019
|
7
11
|
|
8
12
|
* Deprecate domain sharding ([#43](https://github.com/imgix/imgix-rb/pull/43)) ([#45](https://github.com/imgix/imgix-rb/pull/45))
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
Simply initialize a client with a `:host`
|
26
|
+
Simply initialize a client with a `:host` and your `:secure_url_token`. By default, HTTPS URLs are generated, but you can toggle that by passing `use_https: false`.
|
27
27
|
|
28
28
|
Call `Imgix::Client#path` with the resource path to get an `Imgix::Path` object back. You can then manipulate the path parameters, and call `Imgix#Path#to_url` when you're done.
|
29
29
|
|
@@ -47,29 +47,6 @@ path.rect(x: 0, y: 50, width: 200, height: 300).to_url # Rect helper
|
|
47
47
|
```
|
48
48
|
|
49
49
|
|
50
|
-
## Domain Sharded URLs
|
51
|
-
**Warning: Domain Sharding has been deprecated and will be removed in the next major release**<br>
|
52
|
-
To find out more, see our [blog post](https://blog.imgix.com/2019/05/03/deprecating-domain-sharding) explaining the decision to remove this feature.
|
53
|
-
|
54
|
-
Domain sharding enables you to spread image requests across multiple domains. This allows you to bypass the requests-per-host limits of browsers. We recommend 2-3 domain shards maximum if you are going to use domain sharding.
|
55
|
-
|
56
|
-
In order to use domain sharding, you need to add multiple domains to your source. You then provide a list of these domains to a builder.
|
57
|
-
|
58
|
-
|
59
|
-
``` ruby
|
60
|
-
client = Imgix::Client.new(hosts: ['your-subdomain-1.imgix.net',
|
61
|
-
'your-subdomain-2.imgix.net'])
|
62
|
-
```
|
63
|
-
|
64
|
-
By default, shards are calculated using a checksum so that the image path always resolves to the same domain. This improves caching in the browser. However, you can also specify cycle that simply cycles through the domains as you request them.
|
65
|
-
|
66
|
-
|
67
|
-
``` ruby
|
68
|
-
client = Imgix::Client.new(hosts: ['your-subdomain-1.imgix.net',
|
69
|
-
'your-subdomain-2.imgix.net'], shard_strategy: :cycle))
|
70
|
-
```
|
71
|
-
|
72
|
-
|
73
50
|
## Multiple Parameters
|
74
51
|
|
75
52
|
When the imgix api requires multiple parameters you have to use the method rather than an accessor.
|
@@ -103,7 +80,7 @@ For security and diagnostic purposes, we sign all requests with the language and
|
|
103
80
|
This can be disabled by including `include_library_param: false` in the instantiation Hash parameter for `Imgix::Client`:
|
104
81
|
|
105
82
|
```ruby
|
106
|
-
client = Imgix::Client.new(
|
83
|
+
client = Imgix::Client.new(host: 'your-subdomain.imgix.net', include_library_param: false )
|
107
84
|
```
|
108
85
|
|
109
86
|
## Contributing
|
data/lib/imgix.rb
CHANGED
data/lib/imgix/client.rb
CHANGED
@@ -2,23 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'digest'
|
4
4
|
require 'addressable/uri'
|
5
|
-
require 'zlib'
|
6
5
|
require 'net/http'
|
7
6
|
require 'uri'
|
8
7
|
|
9
8
|
module Imgix
|
10
9
|
class Client
|
11
|
-
DEFAULTS = { use_https: true
|
10
|
+
DEFAULTS = { use_https: true }
|
12
11
|
|
13
12
|
def initialize(options = {})
|
14
13
|
options = DEFAULTS.merge(options)
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
@host = options[:host]
|
16
|
+
validate_host!
|
18
17
|
@secure_url_token = options[:secure_url_token]
|
19
18
|
@api_key = options[:api_key]
|
20
19
|
@use_https = options[:use_https]
|
21
|
-
@shard_strategy = options[:shard_strategy] and validate_strategy!
|
22
20
|
@include_library_param = options.fetch(:include_library_param, true)
|
23
21
|
@library = options.fetch(:library_param, "rb")
|
24
22
|
@version = options.fetch(:library_version, Imgix::VERSION)
|
@@ -44,52 +42,19 @@ module Imgix
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def prefix(path)
|
47
|
-
"#{@use_https ? 'https' : 'http'}://#{
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_host(path)
|
51
|
-
host = host_for_crc(path) if @shard_strategy == :crc
|
52
|
-
host = host_for_cycle if @shard_strategy == :cycle
|
53
|
-
host
|
54
|
-
end
|
55
|
-
|
56
|
-
def host_for_crc(path)
|
57
|
-
crc = Zlib.crc32(path)
|
58
|
-
index = crc % @hosts.length - 1
|
59
|
-
@hosts[index]
|
60
|
-
end
|
61
|
-
|
62
|
-
def host_for_cycle
|
63
|
-
if not defined? @hosts_cycle
|
64
|
-
@hosts_cycle = @hosts.cycle
|
65
|
-
end
|
66
|
-
@hosts_cycle.next
|
45
|
+
"#{@use_https ? 'https' : 'http'}://#{@host}"
|
67
46
|
end
|
68
47
|
|
69
48
|
private
|
70
49
|
|
71
|
-
def
|
72
|
-
unless
|
73
|
-
raise ArgumentError
|
50
|
+
def validate_host!
|
51
|
+
unless @host != nil
|
52
|
+
raise ArgumentError, "The :host option must be specified"
|
74
53
|
end
|
75
|
-
|
76
|
-
|
77
|
-
def validate_hosts!
|
78
|
-
unless @hosts.length > 0
|
79
|
-
raise ArgumentError, "The :host or :hosts option must be specified"
|
80
|
-
end
|
81
|
-
@hosts.each do |host|
|
82
|
-
if host.match(DOMAIN_REGEX) == nil
|
83
|
-
raise ArgumentError, "Domains must be passed in as fully-qualified domain names and should not include a protocol or any path element, i.e. \"example.imgix.net\"."
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def deprecate_warning!(host, hosts)
|
89
|
-
has_many_domains = (host.kind_of?(Array) && host.length > 1 ) || (hosts.kind_of?(Array) && hosts.length > 1)
|
90
|
-
if has_many_domains
|
91
|
-
warn "Warning: Domain sharding has been deprecated and will be removed in the next major version."
|
54
|
+
if @host.match(DOMAIN_REGEX) == nil
|
55
|
+
raise ArgumentError, "Domains must be passed in as fully-qualified domain names and should not include a protocol or any path element, i.e. \"example.imgix.net\"."
|
92
56
|
end
|
93
57
|
end
|
58
|
+
|
94
59
|
end
|
95
60
|
end
|
data/lib/imgix/version.rb
CHANGED
data/test/units/domains_test.rb
CHANGED
@@ -3,87 +3,15 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class DomainsTest < Imgix::Test
|
6
|
-
def test_deterministically_choosing_a_path
|
7
|
-
assert_output(nil, "Warning: Domain sharding has been deprecated and will be removed in the next major version.\n"){
|
8
|
-
client = Imgix::Client.new(hosts: [
|
9
|
-
"demos-1.imgix.net",
|
10
|
-
"demos-2.imgix.net",
|
11
|
-
"demos-3.imgix.net",
|
12
|
-
],
|
13
|
-
secure_url_token: '10adc394',
|
14
|
-
include_library_param: false)
|
15
|
-
|
16
|
-
path = client.path('/bridge.png')
|
17
|
-
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
18
|
-
|
19
|
-
path = client.path('/flower.png')
|
20
|
-
assert_equal 'https://demos-2.imgix.net/flower.png?s=02105961388864f85c04121ea7b50e08', path.to_url
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_cycling_choosing_domain_in_order
|
25
|
-
assert_output(nil, "Warning: Domain sharding has been deprecated and will be removed in the next major version.\n"){
|
26
|
-
client = Imgix::Client.new(hosts: [
|
27
|
-
"demos-1.imgix.net",
|
28
|
-
"demos-2.imgix.net",
|
29
|
-
"demos-3.imgix.net",
|
30
|
-
],
|
31
|
-
secure_url_token: '10adc394',
|
32
|
-
shard_strategy: :cycle,
|
33
|
-
include_library_param: false)
|
34
|
-
|
35
|
-
path = client.path('/bridge.png')
|
36
|
-
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
37
|
-
|
38
|
-
path = client.path('/bridge.png')
|
39
|
-
assert_equal 'https://demos-2.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
40
|
-
|
41
|
-
path = client.path('/bridge.png')
|
42
|
-
assert_equal 'https://demos-3.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
43
|
-
|
44
|
-
path = client.path('/bridge.png')
|
45
|
-
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_with_full_paths
|
50
|
-
assert_output(nil, "Warning: Domain sharding has been deprecated and will be removed in the next major version.\n"){
|
51
|
-
client = Imgix::Client.new(hosts: [
|
52
|
-
"demos-1.imgix.net",
|
53
|
-
"demos-2.imgix.net",
|
54
|
-
"demos-3.imgix.net",
|
55
|
-
],
|
56
|
-
secure_url_token: '10adc394',
|
57
|
-
shard_strategy: :cycle,
|
58
|
-
include_library_param: false)
|
59
|
-
|
60
|
-
path = 'https://google.com/cats.gif'
|
61
|
-
assert_equal "https://demos-1.imgix.net/#{CGI.escape(path)}?s=e686099fbba86fc2b8141d3c1ff60605", client.path(path).to_url
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
6
|
def test_invalid_domain_append_slash
|
66
|
-
assert_raises(ArgumentError) {Imgix::Client.new(
|
7
|
+
assert_raises(ArgumentError) {Imgix::Client.new(host: "assets.imgix.net/")}
|
67
8
|
end
|
68
9
|
|
69
10
|
def test_invalid_domain_prepend_scheme
|
70
|
-
assert_raises(ArgumentError) {Imgix::Client.new(
|
11
|
+
assert_raises(ArgumentError) {Imgix::Client.new(host: "https://assets.imgix.net")}
|
71
12
|
end
|
72
13
|
|
73
14
|
def test_invalid_domain_append_dash
|
74
|
-
assert_raises(ArgumentError) {Imgix::Client.new(
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_domain_sharding_deprecation_host
|
78
|
-
|
79
|
-
assert_output(nil, "Warning: Domain sharding has been deprecated and will be removed in the next major version.\n"){
|
80
|
-
Imgix::Client.new(host: ["assets1.imgix.net", "assets2.imgix.net"])
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_domain_sharding_deprecation_hosts
|
85
|
-
assert_output(nil, "Warning: Domain sharding has been deprecated and will be removed in the next major version.\n"){
|
86
|
-
Imgix::Client.new(hosts: ["assets1.imgix.net", "assets2.imgix.net"])
|
87
|
-
}
|
15
|
+
assert_raises(ArgumentError) {Imgix::Client.new(host: "assets.imgix.net-")}
|
88
16
|
end
|
89
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Sutton
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2019-
|
16
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: addressable
|