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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79cf096d23e38b34516352b6d161e9f3991b3c44
4
- data.tar.gz: 30ad381cd316adb07a58bda15228b4e89ce9221e
3
+ metadata.gz: 027c32d72ff3ee11467364ed4771838dc324f134
4
+ data.tar.gz: 6df850a7689330e587aa81f536f4308d7c0cb50f
5
5
  SHA512:
6
- metadata.gz: 9ef40e955e3a043eeafdfacab5ae11a12bff09135caf24aa402925d69e3260f6743f9d26369c9bbbe667e81ab12efdc76adb9468710d4440bf9d4472501093bd
7
- data.tar.gz: 018c2e788a1fc6d3f88c7b84d2231a630d193de2ee3f85a0f0f3e96169f4f3262273864243579fe39e24e3a2692e055eb8d0d6f39387727646c26f73c37c1126
6
+ metadata.gz: 8bc8ca0fafa2733e9c4d2716793c07e3221add977a5870f462410fe414d350b73ac907353a00188fe5457966cec9b624628752f07c663941f9ea0cd46f6b1811
7
+ data.tar.gz: d17301a5b9a127d8cac312eeaca33c01aa2ec9af693f8003acb20334b5425b3667bb815b5e3bdf06a32da2972c047372c5f700191d021345d4d737ac7703ad47
@@ -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 token. You can optionally generate secure URLs.
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
- Now, if you have the URL ready to go, you can call `sign_path` to get the Imgix URL back. If you would like to manipulate the path parameters you can call `path` with the resource path to get an Imgix::Path object back.
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', token: 'your-token', secure: true)
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')
@@ -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 = 'Unofficial Ruby Gem for easily signing imgix URLs.'
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
 
@@ -4,14 +4,14 @@ require 'zlib'
4
4
 
5
5
  module Imgix
6
6
  class Client
7
- DEFAULTS = { secure: false, shard_strategy: :crc }
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
- @token = options[:token]
14
- @secure = options[:secure]
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), @token, 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
- "#{@secure ? 'https' : 'http'}://#{get_host(path)}"
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)
@@ -27,9 +27,9 @@ module Imgix
27
27
  quality: :q
28
28
  }
29
29
 
30
- def initialize(prefix, token, path = '/')
30
+ def initialize(prefix, secure_url_token, path = '/')
31
31
  @prefix = prefix
32
- @token = token
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 @token
47
- # Weird bug in imgix. If there are no params, you still have
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(@token + @path + '?' + query)
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
@@ -1,3 +1,3 @@
1
1
  module Imgix
2
- VERSION = '0.3.5'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -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(:hosts => [
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
- :token => '10adc394',
12
- :include_library_param => false)
11
+ secure_url_token: '10adc394',
12
+ include_library_param: false)
13
13
 
14
14
  path = client.path('/bridge.png')
15
- assert_equal 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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 'http://demos-2.imgix.net/flower.png?&s=7793669cc41d31fd21c26ede9709ef03', path.to_url
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(:hosts => [
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
- :token => '10adc394',
28
- :shard_strategy => :cycle,
29
- :include_library_param => false)
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 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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 'http://demos-2.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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 'http://demos-3.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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(:host =>
46
- "http://demos-1.imgix.net",
47
- :token => '10adc394',
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 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url
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(:hosts => [
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
- :token => '10adc394',
61
- :shard_strategy => :cycle,
62
- :include_library_param => false)
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 "http://demos-1.imgix.net/#{CGI.escape(path)}?&s=4c3ff935011f0d2251800e6a2bb68ee5", client.path(path).to_url
64
+ assert_equal "https://demos-1.imgix.net/#{CGI.escape(path)}?s=e686099fbba86fc2b8141d3c1ff60605", client.path(path).to_url
66
65
  end
67
66
  end
@@ -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 'http://demo.imgix.net/images/demo.png?&s=3c1d676d4daf28c044dd83e8548f834a', path.to_url
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 'http://demo.imgix.net/images/demo.png?&s=3c1d676d4daf28c044dd83e8548f834a', path.to_url
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 = 'http://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
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 = 'http://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
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 = 'http://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a'
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 = 'http://demo.imgix.net/images/demo.png?markalign=middle%2Ccenter&s=f0d0e28a739f022638f4ba6dddf9b694'
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', :include_library_param => false)
57
- url = 'http://demo.imgix.net/images/demo.png?'
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 "http://demo.imgix.net/#{CGI.escape(path)}?&s=4c3ff935011f0d2251800e6a2bb68ee5", client.path(path).to_url
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 "http://demo.imgix.net/#{CGI.escape(path)}?&s=8943817bed50811f6ceedd8f4b84169d", client.path(path).to_url
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(:host => 'demo.imgix.net', :token => '10adc394', :include_library_param => false)
101
+ @client ||= Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: '10adc394', include_library_param: false)
94
102
  end
95
103
  end
@@ -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 = '/images/demo.png'
6
- assert_equal 'http://demo.imgix.net/images/demo.png?&s=3c1d676d4daf28c044dd83e8548f834a', client.sign_path(path)
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 = '/images/demo.png?w=200'
11
- assert_equal 'http://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e', client.sign_path(path)
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 = '/images/demo.png?h=200&w=200'
16
- assert_equal 'http://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a', client.sign_path(path)
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 = '/images/demo.png?w=200&h=200'
19
- assert_equal 'http://demo.imgix.net/images/demo.png?w=200&h=200&s=00b5cde5c7b8bca8618cb911da4ac379', client.sign_path(path)
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(:host => 'demo.imgix.net', :token => '10adc394', :include_library_param => false)
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.3.5
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-08-20 00:00:00.000000000 Z
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.6
80
+ rubygems_version: 2.4.5.1
79
81
  signing_key:
80
82
  specification_version: 4
81
- summary: Unofficial Ruby Gem for easily signing imgix URLs.
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