imgix 2.1.0 → 4.0.3
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 +5 -5
- data/.rubocop.yml +2 -0
- data/.travis.yml +16 -16
- data/.vscode/tasks.json +29 -0
- data/CHANGELOG.md +69 -0
- data/Gemfile +6 -1
- data/README.md +156 -38
- data/Rakefile +2 -0
- data/imgix.gemspec +22 -18
- data/lib/imgix/client.rb +66 -55
- data/lib/imgix/path.rb +197 -45
- data/lib/imgix/version.rb +1 -1
- data/lib/imgix.rb +47 -5
- data/script/bench_path.rb +11 -0
- data/script/bench_to_url.rb +12 -0
- metadata +17 -49
- data/lib/imgix/param_helpers.rb +0 -18
- data/test/test_helper.rb +0 -13
- data/test/units/domains_test.rb +0 -89
- data/test/units/path_test.rb +0 -132
- data/test/units/purge_test.rb +0 -25
- data/test/units/url_test.rb +0 -38
data/test/test_helper.rb
DELETED
data/test/units/domains_test.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
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
|
-
def test_invalid_domain_append_slash
|
66
|
-
assert_raises(ArgumentError) {Imgix::Client.new(hosts: "assets.imgix.net/")}
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_invalid_domain_prepend_scheme
|
70
|
-
assert_raises(ArgumentError) {Imgix::Client.new(hosts: "https://assets.imgix.net")}
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_invalid_domain_append_dash
|
74
|
-
assert_raises(ArgumentError) {Imgix::Client.new(hosts: "assets.imgix.net-")}
|
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
|
-
}
|
88
|
-
end
|
89
|
-
end
|
data/test/units/path_test.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class PathTest < Imgix::Test
|
6
|
-
def test_creating_a_path
|
7
|
-
path = client.path('/images/demo.png')
|
8
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
9
|
-
|
10
|
-
path = client.path('images/demo.png')
|
11
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_signing_path_with_param
|
15
|
-
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
|
16
|
-
path = client.path('/images/demo.png')
|
17
|
-
path.width = 200
|
18
|
-
|
19
|
-
assert_equal url, path.to_url
|
20
|
-
|
21
|
-
path = client.path('/images/demo.png')
|
22
|
-
assert_equal url, path.to_url(w: 200)
|
23
|
-
|
24
|
-
path = client.path('/images/demo.png')
|
25
|
-
assert_equal url, path.width(200).to_url
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_resetting_defaults
|
29
|
-
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
|
30
|
-
path = client.path('/images/demo.png')
|
31
|
-
path.height = 300
|
32
|
-
|
33
|
-
assert_equal url, path.defaults.to_url(w: 200)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_path_with_multiple_params
|
37
|
-
url = 'https://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a'
|
38
|
-
path = client.path('/images/demo.png')
|
39
|
-
|
40
|
-
assert_equal url, path.to_url(h: 200, w: 200)
|
41
|
-
|
42
|
-
path = client.path('/images/demo.png')
|
43
|
-
assert_equal url, path.height(200).width(200).to_url
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_path_with_multi_value_param_safely_encoded
|
47
|
-
url = 'https://demo.imgix.net/images/demo.png?markalign=middle%2Ccenter&s=f0d0e28a739f022638f4ba6dddf9b694'
|
48
|
-
path = client.path('/images/demo.png')
|
49
|
-
|
50
|
-
assert_equal url, path.markalign('middle', 'center').to_url
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_param_keys_are_escaped
|
54
|
-
ix_url = unsigned_client.path('demo.png').to_url({
|
55
|
-
:'hello world' => 'interesting'
|
56
|
-
})
|
57
|
-
|
58
|
-
assert_equal "https://demo.imgix.net/demo.png?hello%20world=interesting", ix_url
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_param_values_are_escaped
|
62
|
-
ix_url = unsigned_client.path('demo.png').to_url({
|
63
|
-
hello_world: '/foo"> <script>alert("hacked")</script><'
|
64
|
-
})
|
65
|
-
|
66
|
-
assert_equal "https://demo.imgix.net/demo.png?hello_world=%2Ffoo%22%3E%20%3Cscript%3Ealert%28%22hacked%22%29%3C%2Fscript%3E%3C", ix_url
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_base64_param_variants_are_base64_encoded
|
70
|
-
ix_url = unsigned_client.path('~text').to_url({
|
71
|
-
txt64: 'I cannøt belîév∑ it wors! 😱'
|
72
|
-
})
|
73
|
-
|
74
|
-
assert_equal "https://demo.imgix.net/~text?txt64=SSBjYW5uw7h0IGJlbMOuw6l24oiRIGl0IHdvcu-jv3MhIPCfmLE", ix_url
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_host_is_required
|
78
|
-
assert_raises(ArgumentError) {Imgix::Client.new}
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_token_is_optional
|
82
|
-
client = Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false)
|
83
|
-
url = 'https://demo.imgix.net/images/demo.png'
|
84
|
-
path = client.path('/images/demo.png')
|
85
|
-
|
86
|
-
assert_equal url, path.to_url
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_https_is_optional
|
90
|
-
client = Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false, use_https: false)
|
91
|
-
url = 'http://demo.imgix.net/images/demo.png'
|
92
|
-
path = client.path('/images/demo.png')
|
93
|
-
|
94
|
-
assert_equal url, path.to_url
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_full_url
|
98
|
-
path = 'https://google.com/cats.gif'
|
99
|
-
|
100
|
-
assert_equal "https://demo.imgix.net/#{CGI.escape(path)}?s=e686099fbba86fc2b8141d3c1ff60605", client.path(path).to_url
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_full_url_with_a_space
|
104
|
-
path = 'https://my-demo-site.com/files/133467012/avatar icon.png'
|
105
|
-
assert_equal "https://demo.imgix.net/#{CGI.escape(path)}?s=35ca40e2e7b6bd208be2c4f7073f658e", client.path(path).to_url
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_include_library_param
|
109
|
-
client = Imgix::Client.new(host: 'demo.imgix.net') # enabled by default
|
110
|
-
url = client.path('/images/demo.png').to_url
|
111
|
-
|
112
|
-
assert_equal "ixlib=rb-#{Imgix::VERSION}", URI(url).query
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_configure_library_param
|
116
|
-
library = "sinatra"
|
117
|
-
version = Imgix::VERSION
|
118
|
-
client = Imgix::Client.new(host: 'demo.imgix.net', library_param: library, library_version: version) # enabled by default
|
119
|
-
url = client.path('/images/demo.png').to_url
|
120
|
-
|
121
|
-
assert_equal "ixlib=#{library}-#{version}", URI(url).query
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
def client
|
126
|
-
@client ||= Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: '10adc394', include_library_param: false)
|
127
|
-
end
|
128
|
-
|
129
|
-
def unsigned_client
|
130
|
-
@unsigned_client ||= Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false)
|
131
|
-
end
|
132
|
-
end
|
data/test/units/purge_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PurgeTest < Imgix::Test
|
4
|
-
def test_runtime_error_without_api_key
|
5
|
-
assert_raises(RuntimeError) {
|
6
|
-
Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false)
|
7
|
-
.purge('https://demo.imgix.net/images/demo.png')
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_successful_purge
|
12
|
-
stub_request(:post, "https://api.imgix.com/v2/image/purger").
|
13
|
-
with(
|
14
|
-
body: {"url"=>"https://demo.imgix.net/images/demo.png"}).
|
15
|
-
to_return(status: 200)
|
16
|
-
|
17
|
-
Imgix::Client.new(host: 'demo.imgix.net', api_key: '10adc394')
|
18
|
-
.purge('/images/demo.png')
|
19
|
-
|
20
|
-
assert_requested :post, 'https://api.imgix.com/v2/image/purger',
|
21
|
-
body: 'url=https%3A%2F%2Fdemo.imgix.net%2Fimages%2Fdemo.png',
|
22
|
-
headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic MTBhZGMzOTQ6', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>"imgix rb-#{ Imgix::VERSION}"},
|
23
|
-
times: 1
|
24
|
-
end
|
25
|
-
end
|
data/test/units/url_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class UrlTest < Imgix::Test
|
6
|
-
DEMO_IMAGE_PATH = '/images/demo.png'
|
7
|
-
|
8
|
-
def test_signing_with_no_params
|
9
|
-
path = client.path(DEMO_IMAGE_PATH)
|
10
|
-
|
11
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_signing_with_one
|
15
|
-
path = client.path(DEMO_IMAGE_PATH)
|
16
|
-
path.width = 200
|
17
|
-
|
18
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e', path.to_url
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_signing_with_multiple_params
|
22
|
-
path = client.path(DEMO_IMAGE_PATH)
|
23
|
-
path.height = 200
|
24
|
-
path.width = 200
|
25
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a', path.to_url
|
26
|
-
|
27
|
-
path = client.path(DEMO_IMAGE_PATH)
|
28
|
-
path.width = 200
|
29
|
-
path.height = 200
|
30
|
-
assert_equal 'https://demo.imgix.net/images/demo.png?w=200&h=200&s=00b5cde5c7b8bca8618cb911da4ac379', path.to_url
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def client
|
36
|
-
@client ||= Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: '10adc394', include_library_param: false)
|
37
|
-
end
|
38
|
-
end
|