imgix 1.1.0 → 1.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: 8c573b0b53304a06886cb1848fd233109975021d
4
- data.tar.gz: ab4b939716370098523381acbcbd3817fdc63b02
3
+ metadata.gz: 2f2350801ae6efed0843066ea4e479508d23d7da
4
+ data.tar.gz: 00df9bd86854aef93cf18f0004d204f9034f30cf
5
5
  SHA512:
6
- metadata.gz: ef8647b9485547eb1af90b6b7d6758099d7028c72745ab55c37f31076a657ed9a4a88872708137b62101bb5b1aa7b940b9673300cc845dc8d72fd9585cac1cd2
7
- data.tar.gz: c0b9567ab4201cb685ce94da7d1d61e2e55af6692d83ac916bfc964e5fca97b1cc4b807071353ab797ea2f803aa0f532cb70dfbd64f97cdd58f8dcec7c4b8b1f
6
+ metadata.gz: fd1bdd5bcee45f9b6fff784aa8603fd9c3781f9cdb94c4382f009fc0ecfc2686021b6e5b92fddc23db4eac47f8d4b131760a4300fa95be1c20bb32b396579329
7
+ data.tar.gz: bda8d65d92c3803a95e36e129b9f64581c0be82064f6d26f4cbd437cab667c402713192d9f335bc687c4a2ba972e6edfb23226d07813940e877f0723f88aecea
@@ -8,4 +8,4 @@ rvm:
8
8
  - 2.2.4
9
9
  - 2.1.8
10
10
  - jruby-9.0.5.0
11
- - rbx-2.11
11
+ - rbx-3.107
@@ -3,6 +3,10 @@
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.2.0] - October 29, 2018
7
+
8
+ * Added `Client#purge` method to allow purging assets from our cache [#37](https://github.com/imgix/imgix-rb/pull/37)
9
+
6
10
  ## [1.1.0] - February 24, 2016
7
11
 
8
12
  * Added automatic Base64 encoding for all Base64 variant parameters.
data/Gemfile CHANGED
@@ -5,4 +5,6 @@ gemspec
5
5
 
6
6
  gem 'rake'
7
7
  gem 'minitest'
8
+ gem 'webmock'
8
9
  gem 'addressable'
10
+ gem 'http'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Imgix
2
2
 
3
- Official Ruby Gem for signing [imgix](http://imgix.com) URLs. Tested under 1.9.2, 2.2.2, JRuby 1.7.19, and Rubinius 2.2.7.
3
+ Official Ruby Gem for signing [imgix](http://imgix.com) URLs. Tested under 2.3.0, 2.2.4, 2.1.8, jruby-9.0.5.0, and rbx-2.11.
4
4
 
5
5
  [![Build Status](https://travis-ci.org/imgix/imgix-rb.png?branch=master)](https://travis-ci.org/imgix/imgix-rb)
6
6
 
@@ -78,6 +78,18 @@ For example to use the noise reduction:
78
78
  path.noise_reduction(50,50)
79
79
  ```
80
80
 
81
+
82
+ ## Purge Cache
83
+
84
+ If you need to remove or update an image on imgix, you can purge it from our cache by initializing a client with your api_key, then calling Imgix::Client#purge with the resource path.
85
+
86
+ ```ruby
87
+ client = Imgix::Client.new(host: 'your-subdomain.imgix.net', api_key: 'your-key')
88
+ client.purge('/images/demo.png')
89
+ ```
90
+
91
+ To learn more about purging assets with imgix, [see our docs](https://docs.imgix.com/setup/purging-images).
92
+
81
93
  ## URL encoding and signed ImgIX URLs
82
94
 
83
95
  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.
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 1.9.0'
22
22
  spec.add_dependency 'addressable'
23
+ spec.add_dependency 'http'
24
+ spec.add_development_dependency 'webmock'
23
25
  end
@@ -1,6 +1,8 @@
1
1
  require 'digest'
2
2
  require 'addressable/uri'
3
3
  require 'zlib'
4
+ require 'net/http'
5
+ require 'uri'
4
6
 
5
7
  module Imgix
6
8
  class Client
@@ -11,6 +13,7 @@ module Imgix
11
13
 
12
14
  @hosts = Array(options[:host]) + Array(options[:hosts]) and validate_hosts!
13
15
  @secure_url_token = options[:secure_url_token]
16
+ @api_key = options[:api_key]
14
17
  @use_https = options[:use_https]
15
18
  @shard_strategy = options[:shard_strategy] and validate_strategy!
16
19
  @include_library_param = options.fetch(:include_library_param, true)
@@ -24,6 +27,19 @@ module Imgix
24
27
  p
25
28
  end
26
29
 
30
+ def purge(path)
31
+ raise "Authentication token required" unless !!(@api_key)
32
+ url = prefix(path)+path
33
+ uri = URI.parse('https://api.imgix.com/v2/image/purger')
34
+ req = Net::HTTP::Post.new(uri.path, {"User-Agent" => "imgix #{@library}-#{@version}"})
35
+ req.basic_auth @api_key, ''
36
+ req.set_form_data({'url' => url})
37
+ sock = Net::HTTP.new(uri.host, uri.port)
38
+ sock.use_ssl = true
39
+ res = sock.start {|http| http.request(req) }
40
+ res
41
+ end
42
+
27
43
  def prefix(path)
28
44
  "#{@use_https ? 'https' : 'http'}://#{get_host(path)}"
29
45
  end
@@ -1,3 +1,3 @@
1
1
  module Imgix
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -4,6 +4,8 @@ Bundler.require :test
4
4
 
5
5
  require 'minitest/autorun'
6
6
  require 'imgix'
7
+ require 'webmock/minitest'
8
+ include WebMock::API
7
9
 
8
10
  class Imgix::Test < MiniTest::Test
9
11
  end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class PurgeTest < Imgix::Test
4
+ def test_runtime_error_without_api_key
5
+ assert_raises(RuntimeError) {
6
+ Imgix::Client.new(host: 'demo.imgix.net', include_library_param: false)
7
+ .purge('https://demo.imgix.net/images/demo.png')
8
+ }
9
+ end
10
+
11
+ def test_successful_purge
12
+ stub_request(:post, "https://api.imgix.com/v2/image/purger").
13
+ with(
14
+ body: {"url"=>"https://demo.imgix.net/images/demo.png"}).
15
+ to_return(status: 200)
16
+
17
+ Imgix::Client.new(host: 'demo.imgix.net', api_key: '10adc394')
18
+ .purge('/images/demo.png')
19
+
20
+ assert_requested :post, 'https://api.imgix.com/v2/image/purger',
21
+ body: 'url=https%3A%2F%2Fdemo.imgix.net%2Fimages%2Fdemo.png',
22
+ headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic MTBhZGMzOTQ6', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>"imgix rb-#{ Imgix::VERSION}"},
23
+ times: 1
24
+ end
25
+ 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: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Sutton
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-24 00:00:00.000000000 Z
15
+ date: 2018-10-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: addressable
@@ -28,6 +28,34 @@ dependencies:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: http
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ - !ruby/object:Gem::Dependency
46
+ name: webmock
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
31
59
  description: Easily create and sign imgix URLs.
32
60
  email:
33
61
  - kelly@imgix.com
@@ -56,6 +84,7 @@ files:
56
84
  - test/test_helper.rb
57
85
  - test/units/domains_test.rb
58
86
  - test/units/path_test.rb
87
+ - test/units/purge_test.rb
59
88
  - test/units/url_test.rb
60
89
  homepage: https://github.com/imgix/imgix-rb
61
90
  licenses:
@@ -77,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
106
  version: '0'
78
107
  requirements: []
79
108
  rubyforge_project:
80
- rubygems_version: 2.4.5.1
109
+ rubygems_version: 2.5.2.3
81
110
  signing_key:
82
111
  specification_version: 4
83
112
  summary: Official Ruby Gem for easily creating and signing imgix URLs.
@@ -85,4 +114,5 @@ test_files:
85
114
  - test/test_helper.rb
86
115
  - test/units/domains_test.rb
87
116
  - test/units/path_test.rb
117
+ - test/units/purge_test.rb
88
118
  - test/units/url_test.rb