imgix 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -4
- data/Readme.markdown +23 -12
- data/lib/imgix/path.rb +5 -4
- data/lib/imgix/version.rb +1 -1
- data/test/units/path_test.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a760faaa0b10815f6507106c11fae9ef28ab574
|
4
|
+
data.tar.gz: f08596f57d3bc94cbc3f30a8f597c858ab154c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 535a0f0626342197b5435564ed7d15af4163b8cbe11c6cba57da5dd6193965a3e0c4cc8f0b795448c7ee8ea1df991a4cdb142134c3c9a33f35adfbb4b8b28158
|
7
|
+
data.tar.gz: 6b41e460a3698bd90a9723fea1ddc43f75db4b6c19f1f5d48e4307aa8a9dee6a1de1e2d6e228c20b53a3bb5a99d406dbe33e2e61dc065c26c4169c62b5c2bd8f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Readme.markdown
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# Imgix
|
2
2
|
|
3
|
-
Unofficial Ruby Gem for signing [imgix](http://imgix.com) URLs.
|
3
|
+
Unofficial Ruby Gem for signing [imgix](http://imgix.com) URLs. Tested under 1.9.2, 2.2.1, JRuby 1.7.19, and Rubinius 2.2.7.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/soffes/imgix-rb.png?branch=master)](https://travis-ci.org/soffes/imgix-rb)
|
4
6
|
|
5
7
|
|
6
8
|
## Installation
|
7
9
|
|
8
10
|
Add this line to your application's Gemfile:
|
9
11
|
|
10
|
-
|
12
|
+
``` ruby
|
13
|
+
gem 'imgix'
|
14
|
+
```
|
11
15
|
|
12
16
|
And then execute:
|
13
17
|
|
@@ -25,7 +29,7 @@ Simply initialize a client with a host and your token. You can optionally genera
|
|
25
29
|
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.
|
26
30
|
|
27
31
|
``` ruby
|
28
|
-
client = Imgix::Client.new(:
|
32
|
+
client = Imgix::Client.new(host: 'your-subdomain.imgix.net', token: 'your-token', secure: true)
|
29
33
|
|
30
34
|
client.sign_path('/images/demo.png?w=200')
|
31
35
|
#=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
|
@@ -46,35 +50,42 @@ path.defaults.width(300).to_url # Resets parameters
|
|
46
50
|
path.rect(x: 0, y: 50, width: 200, height: 300).to_url # Rect helper
|
47
51
|
```
|
48
52
|
|
49
|
-
|
53
|
+
|
54
|
+
## Domain Sharded URLs
|
55
|
+
|
50
56
|
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.
|
51
57
|
|
52
58
|
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.
|
53
59
|
|
54
60
|
|
55
61
|
``` ruby
|
56
|
-
client = Imgix::Client.new(:
|
62
|
+
client = Imgix::Client.new(hosts: ['your-subdomain-1.imgix.net',
|
63
|
+
'your-subdomain-2.imgix.net'])
|
57
64
|
```
|
65
|
+
|
58
66
|
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.
|
59
67
|
|
60
68
|
|
61
69
|
``` ruby
|
62
|
-
client = Imgix::Client.new(:
|
70
|
+
client = Imgix::Client.new(hosts: ['your-subdomain-1.imgix.net',
|
71
|
+
'your-subdomain-2.imgix.net'], shard_strategy: :cycle))
|
63
72
|
```
|
64
|
-
|
73
|
+
|
74
|
+
|
75
|
+
## Multiple Parameters
|
76
|
+
|
65
77
|
When the imgix api requires multiple parameters you have to use the method rather than an accessor.
|
66
|
-
|
78
|
+
|
79
|
+
For example to use the [noise reduction](http://www.imgix.com/docs/urlapi/enhance#nr-nrs) options:
|
67
80
|
|
68
81
|
``` ruby
|
69
82
|
path.noise_reduction(50,50)
|
70
83
|
```
|
71
84
|
|
72
85
|
|
73
|
-
##
|
74
|
-
|
75
|
-
Imgix is tested under 1.9.2, 1.9.3, 2.0.0, JRuby 1.7.2 (1.9 mode), and Rubinius 2.0.0 (1.9 mode).
|
86
|
+
## URL encoding and signed ImgIX URLs
|
76
87
|
|
77
|
-
|
88
|
+
Some important third parties (like Facebook) apply URL escaping to query string components, which can cause correctly signed ImgIX URLs to to be transformed into incorrectly signed ones. We URL encode the query part of the URL before signing, so you don't have to worry about this.
|
78
89
|
|
79
90
|
|
80
91
|
## Contributing
|
data/lib/imgix/path.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi/util'
|
1
2
|
require 'imgix/param_helpers'
|
2
3
|
|
3
4
|
module Imgix
|
@@ -38,7 +39,7 @@ module Imgix
|
|
38
39
|
def to_url(opts={})
|
39
40
|
prev_options = @options.dup
|
40
41
|
@options.merge!(opts)
|
41
|
-
|
42
|
+
|
42
43
|
url = @prefix + path_and_params
|
43
44
|
|
44
45
|
# Weird bug in imgix. If there are no params, you still have
|
@@ -80,7 +81,7 @@ module Imgix
|
|
80
81
|
|
81
82
|
private
|
82
83
|
|
83
|
-
def signature
|
84
|
+
def signature
|
84
85
|
Digest::MD5.hexdigest(@token + @path + '?' + query)
|
85
86
|
end
|
86
87
|
|
@@ -89,7 +90,7 @@ module Imgix
|
|
89
90
|
end
|
90
91
|
|
91
92
|
def query
|
92
|
-
@options.map { |k, v| "#{k.to_s}=#{v}" }.join('&')
|
93
|
+
@options.map { |k, v| "#{k.to_s}=#{CGI.escape(v.to_s)}" }.join('&')
|
93
94
|
end
|
94
95
|
end
|
95
|
-
end
|
96
|
+
end
|
data/lib/imgix/version.rb
CHANGED
data/test/units/path_test.rb
CHANGED
@@ -41,6 +41,13 @@ class PathTest < Imgix::Test
|
|
41
41
|
assert_equal url, path.height(200).width(200).to_url
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_path_with_multi_value_param_safely_encoded
|
45
|
+
url = 'http://demo.imgix.net/images/demo.png?markalign=middle%2Ccenter&s=f0d0e28a739f022638f4ba6dddf9b694'
|
46
|
+
path = client.path('/images/demo.png')
|
47
|
+
|
48
|
+
assert_equal url, path.markalign('middle', 'center').to_url
|
49
|
+
end
|
50
|
+
|
44
51
|
def test_host_is_required
|
45
52
|
assert_raises(ArgumentError) {Imgix::Client.new}
|
46
53
|
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: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.4.5
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Unofficial Ruby Gem for easily signing imgix URLs.
|