imgix 0.1.0 → 0.2.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: f6d90cf96e4d279cd74ac1c314f817036597834c
4
- data.tar.gz: a58e16f0256b02092964d89e2ccc094241ff76f0
3
+ metadata.gz: e7a5b61019c7034e4cab71bccb1506e50523b529
4
+ data.tar.gz: 1fd4f9a95023c58150c616885344659b44d804b5
5
5
  SHA512:
6
- metadata.gz: 1a9b59a69fddf83c0a3ed7ebc47470cbe1f33deb25422831973af740d1290852a1a583ecb76445da478040e9684e01af8d0a00620f895681e2987851c9b4a579
7
- data.tar.gz: 5460ef4d06d0d786e8ea902a18c2c13f7c16c60344c16e01e605e39baec7f71d37cf726bc2fdc5ba36185ec5531eb5d0379b2eac0e9780a097b645c7f6ef3def
6
+ metadata.gz: e60eccc4c267a7cc96fde4b251c5156b30539b8be3a7397785138902e389efcb08b52e4542926895c83b2feeb5764dfa7e44d59917500306fafb01a1333ca83b
7
+ data.tar.gz: 8fff63eb037dd4c223b2e4e6ec6e24c27a1cc398d7cc8bb79ebdb6b3249366b9d5bf7fa1464532e3cce5403bf1618117e88508839d19932f1300b5c9a8b5267f
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-19mode
8
+ - rbx-19mode
@@ -0,0 +1,19 @@
1
+ ## Submitting a Pull Request
2
+
3
+ 1. [Fork the repository.][fork]
4
+ 2. [Create a topic branch.][branch]
5
+ 3. Add tests for your unimplemented feature or bug fix.
6
+ 4. Run `bundle exec rake`. If your tests pass, return to step 3.
7
+ 5. Implement your feature or bug fix.
8
+ 6. Run `bundle exec rake`. If your tests fail, return to step 5.
9
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
10
+ by your tests, return to step 3.
11
+ 8. Add documentation for your feature or bug fix.
12
+ 9. Run `bundle exec rake doc`. If your changes are not 100% documented, go
13
+ back to step 8.
14
+ 10. Add, commit, and push your changes.
15
+ 11. [Submit a pull request.][pr]
16
+
17
+ [fork]: http://help.github.com/fork-a-repo/
18
+ [branch]: http://learn.github.com/p/branching.html
19
+ [pr]: http://help.github.com/send-pull-requests/
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << 'test'
6
6
  t.pattern = 'test/**/*_test.rb'
7
7
  end
8
- task default: :test
8
+ task :default => :test
@@ -1,6 +1,7 @@
1
1
  # Imgix
2
2
 
3
- Ruby Gem for signing [imgix](http://imgix.com) URLs.
3
+ Unofficial Ruby Gem for signing [imgix](http://imgix.com) URLs.
4
+
4
5
 
5
6
  ## Installation
6
7
 
@@ -16,18 +17,42 @@ Or install it yourself as:
16
17
 
17
18
  $ gem install imgix
18
19
 
20
+
19
21
  ## Usage
20
22
 
23
+ Simply initialize a client with a host and your token. You can optionally generate secure URLs.
24
+
25
+ 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
+
21
27
  ``` ruby
22
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', token: 'your-token', secure: true)
28
+ client = Imgix::Client.new(:host => 'your-subdomain.imgix.net', :token => 'your-token', :secure => true)
29
+
23
30
  client.sign_path('/images/demo.png?w=200')
24
- #=> http://foo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e
31
+ #=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
32
+
33
+ # OR
34
+ client.path('/images/demo.png').to_url(w: 200)
35
+
36
+ # OR
37
+ path = client.path('/images/demo.png')
38
+ path.width = 200
39
+ path.to_url
40
+
41
+ # OR
42
+ client.path('/images/demo.png').width(200).height(300).to_url
43
+
44
+ # Some other tricks
45
+ path.defaults.width(300).to_url # Resets parameters
46
+ path.rect(x: 0, y: 50, width: 200, height: 300).to_url # Rect helper
25
47
  ```
26
48
 
49
+ ## Supported Ruby Versions
50
+
51
+ 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).
52
+
53
+ [![Build Status](https://travis-ci.org/soffes/imgix-rb.png?branch=master)](https://travis-ci.org/soffes/imgix-rb)
54
+
55
+
27
56
  ## Contributing
28
57
 
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
58
+ See the [contributing guide](Contributing.markdown).
@@ -6,11 +6,11 @@ require 'imgix/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'imgix'
8
8
  spec.version = Imgix::VERSION
9
- spec.authors = ['Sam Soffes']
10
- spec.email = ['sam@soff.es']
9
+ spec.authors = ['Sam Soffes', 'Ryan LeFevre']
10
+ spec.email = ['sam@soff.es', 'ryan@layervault.com']
11
11
  spec.description = 'Easily sign imgix URLs.'
12
- spec.summary = spec.description
13
- spec.homepage = 'https://github.com/soffes/imgix'
12
+ spec.summary = 'Unofficial Ruby Gem for easily signing imgix URLs.'
13
+ spec.homepage = 'https://github.com/soffes/imgix-rb'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.required_ruby_version = '>= 1.8.7'
21
+ spec.required_ruby_version = '>= 1.9.0'
22
22
  spec.add_dependency 'addressable'
23
23
  end
@@ -1,5 +1,6 @@
1
1
  require 'imgix/version'
2
2
  require 'imgix/client'
3
+ require 'imgix/path'
3
4
 
4
5
  module Imgix
5
6
  end
@@ -6,7 +6,15 @@ module Imgix
6
6
  def initialize(options = {})
7
7
  @host = options[:host]
8
8
  @token = options[:token]
9
- @secure = options[:secure]
9
+ @secure = options[:secure] || false
10
+ end
11
+
12
+ def path(path)
13
+ Path.new(prefix, @token, path)
14
+ end
15
+
16
+ def prefix
17
+ "#{@secure ? 'https' : 'http'}://#{@host}"
10
18
  end
11
19
 
12
20
  def sign_path(path)
@@ -0,0 +1,16 @@
1
+ module Imgix
2
+ module ParamHelpers
3
+ def rect(position)
4
+ @options[:rect] = position and return self if position.is_a?(String)
5
+
6
+ @options[:rect] = [
7
+ position[:x] || position[:left],
8
+ position[:y] || position[:top],
9
+ position[:width] || (position[:right] - position[:left]),
10
+ position[:height] || (position[:bottom] - position[:top])
11
+ ].join(',')
12
+
13
+ return self
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,91 @@
1
+ require 'imgix/param_helpers'
2
+
3
+ module Imgix
4
+ class Path
5
+ include ParamHelpers
6
+
7
+ ALIASES = {
8
+ width: :w,
9
+ height: :h,
10
+ rotation: :rot,
11
+ noise_reduction: :nr,
12
+ sharpness: :sharp,
13
+ exposure: :exp,
14
+ vibrance: :vib,
15
+ saturation: :sat,
16
+ brightness: :bri,
17
+ contrast: :con,
18
+ highlight: :high,
19
+ shadow: :shad,
20
+ gamma: :gam,
21
+ pixelate: :px,
22
+ halftone: :htn,
23
+ watermark: :mark,
24
+ text: :txt,
25
+ format: :fm,
26
+ quality: :q
27
+ }
28
+
29
+ def initialize(prefix, token, path = '/')
30
+ @prefix = prefix
31
+ @token = token
32
+ @path = path
33
+ @options = {}
34
+
35
+ @path = "/#{@path}" if @path[0] != '/'
36
+ end
37
+
38
+ def to_url(opts={})
39
+ prev_options = @options.dup
40
+ @options.merge!(opts)
41
+
42
+ url = @prefix + path_and_params
43
+ url += (@options.length > 0 ? '&' : '') + "s=#{signature}"
44
+
45
+ @options = prev_options
46
+ return url
47
+ end
48
+
49
+ def defaults
50
+ @options = {}
51
+ return self
52
+ end
53
+
54
+ def method_missing(method, *args, &block)
55
+ key = method.to_s.gsub('=', '')
56
+ if args.length == 0
57
+ return @options[key]
58
+ elsif args.first.nil? && @options.has_key?(key)
59
+ @options.delete(key) and return self
60
+ end
61
+
62
+ @options[key] = args.join(',')
63
+ return self
64
+ end
65
+
66
+ ALIASES.each do |from, to|
67
+ define_method from do |*args|
68
+ self.send(to, *args)
69
+ end
70
+
71
+ define_method "#{from}=" do |*args|
72
+ self.send("#{to}=", *args)
73
+ return self
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def signature
80
+ Digest::MD5.hexdigest(@token + @path + '?' + query)
81
+ end
82
+
83
+ def path_and_params
84
+ "#{@path}?#{query}"
85
+ end
86
+
87
+ def query
88
+ @options.map { |k, v| "#{k.to_s}=#{v}" }.join('&')
89
+ end
90
+ end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module Imgix
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class UrlTest < Imgix::Test
4
+ def test_creating_a_path
5
+ path = client.path('/images/demo.png')
6
+ assert_equal 'http://demo.imgix.net/images/demo.png?s=3c1d676d4daf28c044dd83e8548f834a', path.to_url
7
+
8
+ path = client.path('images/demo.png')
9
+ assert_equal 'http://demo.imgix.net/images/demo.png?s=3c1d676d4daf28c044dd83e8548f834a', path.to_url
10
+ end
11
+
12
+ def test_signing_path_with_param
13
+ url = 'http://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
14
+ path = client.path('/images/demo.png')
15
+ path.width = 200
16
+
17
+ assert_equal url, path.to_url
18
+
19
+ path = client.path('/images/demo.png')
20
+ assert_equal url, path.to_url(w: 200)
21
+
22
+ path = client.path('/images/demo.png')
23
+ assert_equal url, path.width(200).to_url
24
+ end
25
+
26
+ def test_resetting_defaults
27
+ url = 'http://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
28
+ path = client.path('/images/demo.png')
29
+ path.height = 300
30
+
31
+ assert_equal url, path.defaults.to_url(w: 200)
32
+ end
33
+
34
+ def test_path_with_multiple_params
35
+ url = 'http://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a'
36
+ path = client.path('/images/demo.png')
37
+
38
+ assert_equal url, path.to_url(h: 200, w: 200)
39
+
40
+ path = client.path('/images/demo.png')
41
+ assert_equal url, path.height(200).width(200).to_url
42
+ end
43
+
44
+ private
45
+
46
+ def client
47
+ @client ||= Imgix::Client.new(:host => 'demo.imgix.net', :token => '10adc394')
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes
8
+ - Ryan LeFevre
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-18 00:00:00.000000000 Z
12
+ date: 2013-07-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: addressable
@@ -27,11 +28,14 @@ dependencies:
27
28
  description: Easily sign imgix URLs.
28
29
  email:
29
30
  - sam@soff.es
31
+ - ryan@layervault.com
30
32
  executables: []
31
33
  extensions: []
32
34
  extra_rdoc_files: []
33
35
  files:
34
36
  - .gitignore
37
+ - .travis.yml
38
+ - Contributing.markdown
35
39
  - Gemfile
36
40
  - LICENSE
37
41
  - Rakefile
@@ -39,10 +43,13 @@ files:
39
43
  - imgix.gemspec
40
44
  - lib/imgix.rb
41
45
  - lib/imgix/client.rb
46
+ - lib/imgix/param_helpers.rb
47
+ - lib/imgix/path.rb
42
48
  - lib/imgix/version.rb
43
49
  - test/test_helper.rb
50
+ - test/units/path_test.rb
44
51
  - test/units/url_test.rb
45
- homepage: https://github.com/soffes/imgix
52
+ homepage: https://github.com/soffes/imgix-rb
46
53
  licenses:
47
54
  - MIT
48
55
  metadata: {}
@@ -54,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
61
  requirements:
55
62
  - - '>='
56
63
  - !ruby/object:Gem::Version
57
- version: 1.8.7
64
+ version: 1.9.0
58
65
  required_rubygems_version: !ruby/object:Gem::Requirement
59
66
  requirements:
60
67
  - - '>='
@@ -65,7 +72,8 @@ rubyforge_project:
65
72
  rubygems_version: 2.0.2
66
73
  signing_key:
67
74
  specification_version: 4
68
- summary: Easily sign imgix URLs.
75
+ summary: Unofficial Ruby Gem for easily signing imgix URLs.
69
76
  test_files:
70
77
  - test/test_helper.rb
78
+ - test/units/path_test.rb
71
79
  - test/units/url_test.rb