imgix 0.3.5 → 1.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 +9 -0
- data/README.md +4 -7
- data/imgix.gemspec +4 -4
- data/lib/imgix/client.rb +5 -16
- data/lib/imgix/path.rb +11 -10
- data/lib/imgix/version.rb +1 -1
- data/test/units/domains_test.rb +22 -23
- data/test/units/path_test.rb +19 -11
- data/test/units/url_test.rb +18 -9
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 027c32d72ff3ee11467364ed4771838dc324f134
|
4
|
+
data.tar.gz: 6df850a7689330e587aa81f536f4308d7c0cb50f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc8ca0fafa2733e9c4d2716793c07e3221add977a5870f462410fe414d350b73ac907353a00188fe5457966cec9b624628752f07c663941f9ea0cd46f6b1811
|
7
|
+
data.tar.gz: d17301a5b9a127d8cac312eeaca33c01aa2ec9af693f8003acb20334b5425b3667bb815b5e3bdf06a32da2972c047372c5f700191d021345d4d737ac7703ad47
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,15 @@
|
|
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
|
+
## [1.0.0] - December 9, 2015
|
7
|
+
### Changed
|
8
|
+
- Removed `Client#sign_path` to provide a consistent method and code path for generating URLs. [#16](https://github.com/imgix/imgix-rb/issues/16)
|
9
|
+
- Changed `:secure` option to the more clear `:use_https` [#11](https://github.com/imgix/imgix-rb/issues/11)
|
10
|
+
- Changed `:token` option to the more clear `:secure_url_token` [#11](https://github.com/imgix/imgix-rb/issues/11)
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Fixed URL query strings beginning with `?&s=` instead of `?s=` when no other params are present. [#15](https://github.com/imgix/imgix-rb/issues/15)
|
14
|
+
|
6
15
|
## [0.3.3] - May 14, 2015
|
7
16
|
### Fixed
|
8
17
|
- Fixed a bug where URLs as the path component for Web Proxy sources would not be encoded would generate URLs that would result in a 400 Bad Request. [#8](https://github.com/imgix/imgix-rb/pull/8)
|
data/README.md
CHANGED
@@ -23,18 +23,15 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
Simply initialize a client with a host and your
|
26
|
+
Simply initialize a client with a `:host` or `:hosts` 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
|
|
30
30
|
``` ruby
|
31
|
-
client = Imgix::Client.new(host: 'your-subdomain.imgix.net',
|
31
|
+
client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
|
32
32
|
|
33
|
-
client.sign_path('/images/demo.png?w=200')
|
34
|
-
#=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
|
35
|
-
|
36
|
-
# OR
|
37
33
|
client.path('/images/demo.png').to_url(w: 200)
|
34
|
+
#=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
|
38
35
|
|
39
36
|
# OR
|
40
37
|
path = client.path('/images/demo.png')
|
data/imgix.gemspec
CHANGED
@@ -6,10 +6,10 @@ require 'imgix/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'imgix'
|
8
8
|
spec.version = Imgix::VERSION
|
9
|
-
spec.authors = ['Kelly Sutton', 'Sam Soffes', 'Ryan LeFevre', 'Antony Denyer']
|
10
|
-
spec.email = ['kelly@imgix.com', 'sam@soff.es', 'ryan@layervault.com', 'email@antonydenyer.co.uk']
|
11
|
-
spec.description = 'Easily sign imgix URLs.'
|
12
|
-
spec.summary = '
|
9
|
+
spec.authors = ['Kelly Sutton', 'Sam Soffes', 'Ryan LeFevre', 'Antony Denyer', 'Paul Straw']
|
10
|
+
spec.email = ['kelly@imgix.com', 'sam@soff.es', 'ryan@layervault.com', 'email@antonydenyer.co.uk', 'paul@imgix.com']
|
11
|
+
spec.description = 'Easily create and sign imgix URLs.'
|
12
|
+
spec.summary = 'Official Ruby Gem for easily creating and signing imgix URLs.'
|
13
13
|
spec.homepage = 'https://github.com/imgix/imgix-rb'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
data/lib/imgix/client.rb
CHANGED
@@ -4,14 +4,14 @@ require 'zlib'
|
|
4
4
|
|
5
5
|
module Imgix
|
6
6
|
class Client
|
7
|
-
DEFAULTS = {
|
7
|
+
DEFAULTS = { use_https: true, shard_strategy: :crc }
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
options = DEFAULTS.merge(options)
|
11
11
|
|
12
12
|
@hosts = Array(options[:host]) + Array(options[:hosts]) and validate_hosts!
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@secure_url_token = options[:secure_url_token]
|
14
|
+
@use_https = options[:use_https]
|
15
15
|
@shard_strategy = options[:shard_strategy] and validate_strategy!
|
16
16
|
@include_library_param = options.fetch(:include_library_param, true)
|
17
17
|
@library = options.fetch(:library_param, "rb")
|
@@ -19,24 +19,13 @@ module Imgix
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def path(path)
|
22
|
-
p = Path.new(prefix(path), @
|
22
|
+
p = Path.new(prefix(path), @secure_url_token, path)
|
23
23
|
p.ixlib("#{@library}-#{@version}") if @include_library_param
|
24
24
|
p
|
25
25
|
end
|
26
26
|
|
27
27
|
def prefix(path)
|
28
|
-
"#{@
|
29
|
-
end
|
30
|
-
|
31
|
-
def sign_path(path)
|
32
|
-
uri = Addressable::URI.parse(path)
|
33
|
-
query = (uri.query || '')
|
34
|
-
path = "#{@secure ? 'https' : 'http'}://#{get_host(path)}#{uri.path}?#{query}"
|
35
|
-
if @token
|
36
|
-
signature = Digest::MD5.hexdigest(@token + uri.path + '?' + query)
|
37
|
-
path += "&s=#{signature}"
|
38
|
-
end
|
39
|
-
return path
|
28
|
+
"#{@use_https ? 'https' : 'http'}://#{get_host(path)}"
|
40
29
|
end
|
41
30
|
|
42
31
|
def get_host(path)
|
data/lib/imgix/path.rb
CHANGED
@@ -27,9 +27,9 @@ module Imgix
|
|
27
27
|
quality: :q
|
28
28
|
}
|
29
29
|
|
30
|
-
def initialize(prefix,
|
30
|
+
def initialize(prefix, secure_url_token, path = '/')
|
31
31
|
@prefix = prefix
|
32
|
-
@
|
32
|
+
@secure_url_token = secure_url_token
|
33
33
|
@path = path
|
34
34
|
@options = {}
|
35
35
|
|
@@ -37,17 +37,14 @@ module Imgix
|
|
37
37
|
@path = "/#{@path}" if @path[0] != '/'
|
38
38
|
end
|
39
39
|
|
40
|
-
def to_url(opts={})
|
40
|
+
def to_url(opts = {})
|
41
41
|
prev_options = @options.dup
|
42
42
|
@options.merge!(opts)
|
43
43
|
|
44
44
|
url = @prefix + path_and_params
|
45
45
|
|
46
|
-
if @
|
47
|
-
|
48
|
-
# to put & in front of the signature or else you will get
|
49
|
-
# unauthorized.
|
50
|
-
url += "&s=#{signature}"
|
46
|
+
if @secure_url_token
|
47
|
+
url += (has_query? ? '&' : '?') + "s=#{signature}"
|
51
48
|
end
|
52
49
|
|
53
50
|
@options = prev_options
|
@@ -85,15 +82,19 @@ module Imgix
|
|
85
82
|
private
|
86
83
|
|
87
84
|
def signature
|
88
|
-
Digest::MD5.hexdigest(@
|
85
|
+
Digest::MD5.hexdigest(@secure_url_token + path_and_params)
|
89
86
|
end
|
90
87
|
|
91
88
|
def path_and_params
|
92
|
-
"#{@path}?#{query}"
|
89
|
+
has_query? ? "#{@path}?#{query}" : @path
|
93
90
|
end
|
94
91
|
|
95
92
|
def query
|
96
93
|
@options.map { |k, v| "#{k.to_s}=#{CGI.escape(v.to_s)}" }.join('&')
|
97
94
|
end
|
95
|
+
|
96
|
+
def has_query?
|
97
|
+
query.length > 0
|
98
|
+
end
|
98
99
|
end
|
99
100
|
end
|
data/lib/imgix/version.rb
CHANGED
data/test/units/domains_test.rb
CHANGED
@@ -3,65 +3,64 @@ require 'test_helper'
|
|
3
3
|
class DomainsTest < Imgix::Test
|
4
4
|
|
5
5
|
def test_deterministically_choosing_a_path
|
6
|
-
client = Imgix::Client.new(:
|
6
|
+
client = Imgix::Client.new(hosts: [
|
7
7
|
"demos-1.imgix.net",
|
8
8
|
"demos-2.imgix.net",
|
9
9
|
"demos-3.imgix.net",
|
10
10
|
],
|
11
|
-
:
|
12
|
-
:
|
11
|
+
secure_url_token: '10adc394',
|
12
|
+
include_library_param: false)
|
13
13
|
|
14
14
|
path = client.path('/bridge.png')
|
15
|
-
assert_equal '
|
15
|
+
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
16
16
|
|
17
17
|
path = client.path('/flower.png')
|
18
|
-
assert_equal '
|
18
|
+
assert_equal 'https://demos-2.imgix.net/flower.png?s=02105961388864f85c04121ea7b50e08', path.to_url
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_cycling_choosing_domain_in_order
|
22
|
-
client = Imgix::Client.new(:
|
22
|
+
client = Imgix::Client.new(hosts: [
|
23
23
|
"demos-1.imgix.net",
|
24
24
|
"demos-2.imgix.net",
|
25
25
|
"demos-3.imgix.net",
|
26
26
|
],
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
27
|
+
secure_url_token: '10adc394',
|
28
|
+
shard_strategy: :cycle,
|
29
|
+
include_library_param: false)
|
30
30
|
|
31
31
|
path = client.path('/bridge.png')
|
32
|
-
assert_equal '
|
32
|
+
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
33
33
|
|
34
34
|
path = client.path('/bridge.png')
|
35
|
-
assert_equal '
|
35
|
+
assert_equal 'https://demos-2.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
36
36
|
|
37
37
|
path = client.path('/bridge.png')
|
38
|
-
assert_equal '
|
38
|
+
assert_equal 'https://demos-3.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
39
39
|
|
40
40
|
path = client.path('/bridge.png')
|
41
|
-
assert_equal '
|
41
|
+
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_strips_out_protocol
|
45
|
-
client = Imgix::Client.new(:
|
46
|
-
|
47
|
-
|
48
|
-
:include_library_param => false)
|
45
|
+
client = Imgix::Client.new(host: "http://demos-1.imgix.net",
|
46
|
+
secure_url_token: '10adc394',
|
47
|
+
include_library_param: false)
|
49
48
|
|
50
49
|
path = client.path('/bridge.png')
|
51
|
-
assert_equal '
|
50
|
+
assert_equal 'https://demos-1.imgix.net/bridge.png?s=0233fd6de51f20f11cff6b452b7a9a05', path.to_url
|
52
51
|
end
|
53
52
|
|
54
53
|
def test_with_full_paths
|
55
|
-
client = Imgix::Client.new(:
|
54
|
+
client = Imgix::Client.new(hosts: [
|
56
55
|
"demos-1.imgix.net",
|
57
56
|
"demos-2.imgix.net",
|
58
57
|
"demos-3.imgix.net",
|
59
58
|
],
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
59
|
+
secure_url_token: '10adc394',
|
60
|
+
shard_strategy: :cycle,
|
61
|
+
include_library_param: false)
|
63
62
|
|
64
63
|
path = 'https://google.com/cats.gif'
|
65
|
-
assert_equal "
|
64
|
+
assert_equal "https://demos-1.imgix.net/#{CGI.escape(path)}?s=e686099fbba86fc2b8141d3c1ff60605", client.path(path).to_url
|
66
65
|
end
|
67
66
|
end
|
data/test/units/path_test.rb
CHANGED
@@ -3,14 +3,14 @@ require 'test_helper'
|
|
3
3
|
class PathTest < Imgix::Test
|
4
4
|
def test_creating_a_path
|
5
5
|
path = client.path('/images/demo.png')
|
6
|
-
assert_equal '
|
6
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
7
7
|
|
8
8
|
path = client.path('images/demo.png')
|
9
|
-
assert_equal '
|
9
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_signing_path_with_param
|
13
|
-
url = '
|
13
|
+
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
|
14
14
|
path = client.path('/images/demo.png')
|
15
15
|
path.width = 200
|
16
16
|
|
@@ -24,7 +24,7 @@ class PathTest < Imgix::Test
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_resetting_defaults
|
27
|
-
url = '
|
27
|
+
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
|
28
28
|
path = client.path('/images/demo.png')
|
29
29
|
path.height = 300
|
30
30
|
|
@@ -32,7 +32,7 @@ class PathTest < Imgix::Test
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_path_with_multiple_params
|
35
|
-
url = '
|
35
|
+
url = 'https://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a'
|
36
36
|
path = client.path('/images/demo.png')
|
37
37
|
|
38
38
|
assert_equal url, path.to_url(h: 200, w: 200)
|
@@ -42,7 +42,7 @@ class PathTest < Imgix::Test
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_path_with_multi_value_param_safely_encoded
|
45
|
-
url = '
|
45
|
+
url = 'https://demo.imgix.net/images/demo.png?markalign=middle%2Ccenter&s=f0d0e28a739f022638f4ba6dddf9b694'
|
46
46
|
path = client.path('/images/demo.png')
|
47
47
|
|
48
48
|
assert_equal url, path.markalign('middle', 'center').to_url
|
@@ -53,8 +53,16 @@ class PathTest < Imgix::Test
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_token_is_optional
|
56
|
-
client = Imgix::Client.new(host: 'demo.imgix.net', :
|
57
|
-
url = '
|
56
|
+
client = Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false)
|
57
|
+
url = 'https://demo.imgix.net/images/demo.png'
|
58
|
+
path = client.path('/images/demo.png')
|
59
|
+
|
60
|
+
assert_equal url, path.to_url
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_https_is_optional
|
64
|
+
client = Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false, use_https: false)
|
65
|
+
url = 'http://demo.imgix.net/images/demo.png'
|
58
66
|
path = client.path('/images/demo.png')
|
59
67
|
|
60
68
|
assert_equal url, path.to_url
|
@@ -63,12 +71,12 @@ class PathTest < Imgix::Test
|
|
63
71
|
def test_full_url
|
64
72
|
path = 'https://google.com/cats.gif'
|
65
73
|
|
66
|
-
assert_equal "
|
74
|
+
assert_equal "https://demo.imgix.net/#{CGI.escape(path)}?s=e686099fbba86fc2b8141d3c1ff60605", client.path(path).to_url
|
67
75
|
end
|
68
76
|
|
69
77
|
def test_full_url_with_a_space
|
70
78
|
path = 'https://my-demo-site.com/files/133467012/avatar icon.png'
|
71
|
-
assert_equal "
|
79
|
+
assert_equal "https://demo.imgix.net/#{CGI.escape(path)}?s=35ca40e2e7b6bd208be2c4f7073f658e", client.path(path).to_url
|
72
80
|
end
|
73
81
|
|
74
82
|
def test_include_library_param
|
@@ -90,6 +98,6 @@ class PathTest < Imgix::Test
|
|
90
98
|
private
|
91
99
|
|
92
100
|
def client
|
93
|
-
@client ||= Imgix::Client.new(:
|
101
|
+
@client ||= Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: '10adc394', include_library_param: false)
|
94
102
|
end
|
95
103
|
end
|
data/test/units/url_test.rb
CHANGED
@@ -1,27 +1,36 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class UrlTest < Imgix::Test
|
4
|
+
DEMO_IMAGE_PATH = '/images/demo.png'
|
5
|
+
|
4
6
|
def test_signing_with_no_params
|
5
|
-
path =
|
6
|
-
|
7
|
+
path = client.path(DEMO_IMAGE_PATH)
|
8
|
+
|
9
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?s=2c7c157eaf23b06a0deb2f60b81938c4', path.to_url
|
7
10
|
end
|
8
11
|
|
9
12
|
def test_signing_with_one
|
10
|
-
path =
|
11
|
-
|
13
|
+
path = client.path(DEMO_IMAGE_PATH)
|
14
|
+
path.width = 200
|
15
|
+
|
16
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e', path.to_url
|
12
17
|
end
|
13
18
|
|
14
19
|
def test_signing_with_multiple_params
|
15
|
-
path =
|
16
|
-
|
20
|
+
path = client.path(DEMO_IMAGE_PATH)
|
21
|
+
path.height = 200
|
22
|
+
path.width = 200
|
23
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a', path.to_url
|
17
24
|
|
18
|
-
path =
|
19
|
-
|
25
|
+
path = client.path(DEMO_IMAGE_PATH)
|
26
|
+
path.width = 200
|
27
|
+
path.height = 200
|
28
|
+
assert_equal 'https://demo.imgix.net/images/demo.png?w=200&h=200&s=00b5cde5c7b8bca8618cb911da4ac379', path.to_url
|
20
29
|
end
|
21
30
|
|
22
31
|
private
|
23
32
|
|
24
33
|
def client
|
25
|
-
@client ||= Imgix::Client.new(:
|
34
|
+
@client ||= Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: '10adc394', include_library_param: false)
|
26
35
|
end
|
27
36
|
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Sutton
|
8
8
|
- Sam Soffes
|
9
9
|
- Ryan LeFevre
|
10
10
|
- Antony Denyer
|
11
|
+
- Paul Straw
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date: 2015-
|
15
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: addressable
|
@@ -27,12 +28,13 @@ dependencies:
|
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: '0'
|
30
|
-
description: Easily sign imgix URLs.
|
31
|
+
description: Easily create and sign imgix URLs.
|
31
32
|
email:
|
32
33
|
- kelly@imgix.com
|
33
34
|
- sam@soff.es
|
34
35
|
- ryan@layervault.com
|
35
36
|
- email@antonydenyer.co.uk
|
37
|
+
- paul@imgix.com
|
36
38
|
executables: []
|
37
39
|
extensions: []
|
38
40
|
extra_rdoc_files: []
|
@@ -75,10 +77,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
77
|
version: '0'
|
76
78
|
requirements: []
|
77
79
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.4.
|
80
|
+
rubygems_version: 2.4.5.1
|
79
81
|
signing_key:
|
80
82
|
specification_version: 4
|
81
|
-
summary:
|
83
|
+
summary: Official Ruby Gem for easily creating and signing imgix URLs.
|
82
84
|
test_files:
|
83
85
|
- test/test_helper.rb
|
84
86
|
- test/units/domains_test.rb
|