imgix 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/Rakefile +8 -0
- data/Readme.markdown +33 -0
- data/imgix.gemspec +23 -0
- data/lib/imgix.rb +5 -0
- data/lib/imgix/client.rb +19 -0
- data/lib/imgix/version.rb +3 -0
- data/test/test_helper.rb +9 -0
- data/test/units/url_test.rb +27 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6d90cf96e4d279cd74ac1c314f817036597834c
|
4
|
+
data.tar.gz: a58e16f0256b02092964d89e2ccc094241ff76f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a9b59a69fddf83c0a3ed7ebc47470cbe1f33deb25422831973af740d1290852a1a583ecb76445da478040e9684e01af8d0a00620f895681e2987851c9b4a579
|
7
|
+
data.tar.gz: 5460ef4d06d0d786e8ea902a18c2c13f7c16c60344c16e01e605e39baec7f71d37cf726bc2fdc5ba36185ec5531eb5d0379b2eac0e9780a097b645c7f6ef3def
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sam Soffes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/Readme.markdown
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Imgix
|
2
|
+
|
3
|
+
Ruby Gem for signing [imgix](http://imgix.com) URLs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'imgix'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install imgix
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
client = Imgix::Client.new(host: 'your-subdomain.imgix.net', token: 'your-token', secure: true)
|
23
|
+
client.sign_path('/images/demo.png?w=200')
|
24
|
+
#=> http://foo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/imgix.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'imgix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'imgix'
|
8
|
+
spec.version = Imgix::VERSION
|
9
|
+
spec.authors = ['Sam Soffes']
|
10
|
+
spec.email = ['sam@soff.es']
|
11
|
+
spec.description = 'Easily sign imgix URLs.'
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/soffes/imgix'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 1.8.7'
|
22
|
+
spec.add_dependency 'addressable'
|
23
|
+
end
|
data/lib/imgix.rb
ADDED
data/lib/imgix/client.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'addressable/uri'
|
3
|
+
|
4
|
+
module Imgix
|
5
|
+
class Client
|
6
|
+
def initialize(options = {})
|
7
|
+
@host = options[:host]
|
8
|
+
@token = options[:token]
|
9
|
+
@secure = options[:secure]
|
10
|
+
end
|
11
|
+
|
12
|
+
def sign_path(path)
|
13
|
+
uri = Addressable::URI.parse(path)
|
14
|
+
query = (uri.query || '')
|
15
|
+
signature = Digest::MD5.hexdigest(@token + uri.path + '?' + query)
|
16
|
+
"#{@secure ? 'https' : 'http'}://#{@host}#{uri.path}?#{query}#{query.length > 0 ? '&' : ''}s=#{signature}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UrlTest < Imgix::Test
|
4
|
+
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
|
+
end
|
8
|
+
|
9
|
+
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)
|
12
|
+
end
|
13
|
+
|
14
|
+
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)
|
17
|
+
|
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)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def client
|
25
|
+
@client ||= Imgix::Client.new(:host => 'demo.imgix.net', :token => '10adc394')
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imgix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Soffes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Easily sign imgix URLs.
|
28
|
+
email:
|
29
|
+
- sam@soff.es
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- Rakefile
|
38
|
+
- Readme.markdown
|
39
|
+
- imgix.gemspec
|
40
|
+
- lib/imgix.rb
|
41
|
+
- lib/imgix/client.rb
|
42
|
+
- lib/imgix/version.rb
|
43
|
+
- test/test_helper.rb
|
44
|
+
- test/units/url_test.rb
|
45
|
+
homepage: https://github.com/soffes/imgix
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.8.7
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.0.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Easily sign imgix URLs.
|
69
|
+
test_files:
|
70
|
+
- test/test_helper.rb
|
71
|
+
- test/units/url_test.rb
|