imgix 3.2.1 → 3.3.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
- SHA1:
3
- metadata.gz: 6bdd9b0132a6ca25ef31c4329cb9208b4797509e
4
- data.tar.gz: 33b0aa5a0b0db17caba521df0c0795b018f7042e
2
+ SHA256:
3
+ metadata.gz: aacdd5bdf7d625eec3ee921e77ae5abc4ce477d3acb3fe157cd8dfbba17c290b
4
+ data.tar.gz: fe73df2f92e6fdbba85ea88bf5354e0a3ae312f2d5d7807cf2d1e7d2085571d5
5
5
  SHA512:
6
- metadata.gz: 0cb3543b4cf85f1d8226f1d9b994265936c9ff08c8db12f9d0f72f75eaa6852c26ca20fefc095935c2b3162e4c81402510df1f554507341a83ffda4f6945ee8d
7
- data.tar.gz: 4089e89e2b128bf031e300f38e8686a77606f0ee8a60233d83ee89827efebf728ae86be88053ecaadb044c1f44ae9eb4c6dc1377b1f98b7587b1b680478f881f
6
+ metadata.gz: c61d6b8c35bc9ad6133eb72829be8afccb9aec4822775a2df0649b5c2536ba97a8b28884cc2559d3764b9cd66dd1dcd38dca8356be43f66dd8a3157e0c66db49
7
+ data.tar.gz: f08aab23f7211ee429f017a9ac38f9bcf6c67fd2290814b1c7503f02d3e29a6265b7f171afbe23ccd09be37fd2083104d35ea8de59c17eaf1bc764ab24468db9
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Describe the bug**
13
+ A clear and concise description of what the bug is.
14
+
15
+ **To Reproduce**
16
+ Steps to reproduce the behavior:
17
+
18
+ **Expected behavior**
19
+ A clear and concise description of what you expected to happen.
20
+
21
+ **Screenshots**
22
+ If applicable, add screenshots to help explain your problem.
23
+
24
+ **Information:**
25
+ - imgix-rb version: [e.g. 2.0.0]
26
+
27
+ **Additional context**
28
+ Add any other context about the problem here.
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Before you submit:**
13
+
14
+ - [ ] Please search through the [existing issues](https://github.com/imgix/imgix-rb/issues?utf8=%E2%9C%93&q=is%3Aissue) to see if your feature has already been discussed.
15
+ - [ ] Please take a moment to find out whether your idea fits with the scope and aims of this project.
16
+
17
+ **Is your feature request related to a problem? Please describe.**
18
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
19
+
20
+ **Describe the solution you'd like**
21
+ A clear and concise description of what you want to happen.
22
+
23
+ **Describe alternatives you've considered**
24
+ A clear and concise description of any alternative solutions or features you've considered.
25
+
26
+ **Additional context**
27
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Question
3
+ about: Ask a question about the project
4
+ title: ''
5
+ labels: ''
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Before you submit:**
13
+
14
+ - [ ] Please search through the [existing issues]([existing issues](https://github.com/imgix/imgix-rb/issues?utf8=%E2%9C%93&q=is%3Aissue)) to see if your question has already been discussed.
15
+
16
+ **Question**
17
+ A clear and concise description of your question.
@@ -0,0 +1,73 @@
1
+ <!--
2
+ Hello, and thanks for contributing to imgix-rb! 🎉🙌
3
+ Please take a second to fill out PRs with the following template!
4
+ -->
5
+
6
+ # Description
7
+
8
+ <!-- What is accomplished by this PR? If there is something potentially controversial in your PR, please take a moment to tell us about your choices. -->
9
+
10
+ <!--
11
+ Please use the checklist that is most closely related to your PR, and delete the other checklists. -->
12
+
13
+ ## Checklist: Fixing typos/Doc change
14
+
15
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
16
+
17
+ ## Checklist: Bug Fix
18
+
19
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
20
+ - [ ] All existing unit tests are still passing (if applicable)
21
+ - [ ] Add new passing unit tests to cover the code introduced by your PR
22
+ - [ ] Update the readme
23
+ - [ ] Update or add any necessary API documentation
24
+ - [ ] Add some [steps](#steps-to-test) so we can test your bug fix
25
+
26
+ ## Checklist: New Feature
27
+
28
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
29
+ - [ ] Any breaking changes are specified on the commit on which they are introduced with `BREAKING CHANGE` in the body of the commit.
30
+ - [ ] If this is a big feature with breaking changes, consider [opening an issue][issues] to discuss first. This is completely up to you, but please keep in mind that your PR might not be accepted.
31
+ - [ ] Run unit tests to ensure all existing tests are still passing
32
+ - [ ] Add new passing unit tests to cover the code introduced by your PR
33
+ - [ ] Update the readme
34
+ - [ ] Add some [steps](#steps-to-test) so we can test your cool new feature!
35
+
36
+ ## Steps to Test
37
+
38
+ <!-- Delete this selction if you are just submitting a doc change/small fix -->
39
+
40
+ <!-- A code example or a set of steps is preferred -->
41
+
42
+ Related issue: [e.g. #42]
43
+
44
+ Code:
45
+
46
+ ```rb
47
+ // A standalone Ruby example of what the PR solves
48
+ ```
49
+
50
+ <!-- A link to a codepen/codesandbox is also an option. -->
51
+
52
+ <!--
53
+
54
+ ## Conventional Commit Spec
55
+
56
+ PR titles should be in the format `<type>(<scope>): <description>`. For example: `chore(readme): fix typo`
57
+
58
+ `type` can be any of the follow:
59
+ - `feat`: a feature, or breaking change
60
+ - `fix`: a bug-fix
61
+ - `test`: Adding missing tests or correcting existing tests
62
+ - `docs`: documentation only changes (readme, changelog, contributing guide)
63
+ - `refactor`: a code change that neither fixes a bug nor adds a feature
64
+ - `chore`: reoccurring tasks for project maintainability (example scopes: release, deps)
65
+ - `config`: changes to tooling configurations used in the project
66
+ - `build`: changes that affect the build system or external dependencies (example scopes: npm, bundler, gradle)
67
+ - `ci`: changes to CI configuration files and scripts (example scopes: travis)
68
+ - `perf`: a code change that improves performance
69
+ - `style`: changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
70
+
71
+ `scope` is optional, and can be anything.
72
+ `description` should be a short description of the change, written in the imperative-mood.
73
+ -->
@@ -5,5 +5,17 @@ rvm:
5
5
  - 2.3.0
6
6
  - 2.2.4
7
7
  - 2.1.8
8
- - jruby-9.0.5.0
9
- - rbx-3.107
8
+ - jruby-9.2.11.0
9
+
10
+ jobs:
11
+ # Use `fast_finish`, don't wait for any allowed failures.
12
+ fast_finish: true
13
+
14
+ include:
15
+ - name: Rubinius
16
+ rvm: rbx-3.107
17
+ dist: trusty
18
+
19
+ allow_failures:
20
+ - name: Rubinius
21
+
@@ -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
+ ## [3.3.0](https://github.com/imgix/imgix-rb/compare/3.2.1...3.3.0) - July 21, 2020
7
+
8
+ * fix: warn prefix-with-args is deprecated ([#78](https://github.com/imgix/imgix-rb/pull/78))
9
+ * fix: warn host has been deprecated in favor of domain ([#76](https://github.com/imgix/imgix-rb/pull/76))
10
+ * fix: deprecate ALIASES and corresponding define_method(s) ([#75](https://github.com/imgix/imgix-rb/pull/75))
11
+ * fix: deprecate ParamHelpers.rect ([#74](https://github.com/imgix/imgix-rb/pull/74))
12
+ * fix: allow rbx-3.107 to fail (travis-config) ([#70](https://github.com/imgix/imgix-rb/pull/70))
13
+ * fix: remove ensure even requirement ([#69](https://github.com/imgix/imgix-rb/pull/69))
14
+
6
15
  ## [3.2.1](https://github.com/imgix/imgix-rb/compare/3.2.0...3.2.1) - November 15, 2019
7
16
 
8
17
  * fix: duplicate entries when using `min_width` or `max_width` ([#59](https://github.com/imgix/imgix-rb/pull/59))
data/README.md CHANGED
@@ -1,8 +1,29 @@
1
- # Imgix
2
-
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
-
5
- [![Build Status](https://travis-ci.org/imgix/imgix-rb.svg?branch=master)](https://travis-ci.org/imgix/imgix-rb)
1
+ <!-- ix-docs-ignore -->
2
+ ![imgix logo](https://assets.imgix.net/sdk-imgix-logo.svg)
3
+
4
+ `imgix-rb` is a client library for generating image URLs with [imgix](https://www.imgix.com/). It is tested under Ruby versions `2.3.0`, `2.2.4`, `2.1.8`, `jruby-9.2.11.0`, and `rbx-3.107`.
5
+
6
+ [![Gem Version](https://img.shields.io/gem/v/imgix.svg)](https://rubygems.org/gems/imgix)
7
+ [![Build Status](https://travis-ci.org/imgix/imgix-rb.svg?branch=main)](https://travis-ci.org/imgix/imgix-rb)
8
+ ![Downloads](https://img.shields.io/gem/dt/imgix)
9
+ [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/imgix/imgix-rb/blob/main/LICENSE)
10
+
11
+ ---
12
+ <!-- /ix-docs-ignore -->
13
+
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [Srcset Generation](#srcset-generation)
17
+ - [Fixed image rendering](#fixed-image-rendering)
18
+ - [Custom Widths](#custom-widths)
19
+ - [Width Tolerance](#width-tolerance)
20
+ - [Minimum and Maximum Width Ranges](#minimum-and-maximum-width-ranges)
21
+ - [Variable Qualities](#variable-qualities)
22
+ - [Multiple Parameters](#multiple-parameters)
23
+ - [Purge Cache](#purge-cache)
24
+ - [URL encoding and signed imgix URLs](#url-encoding-and-signed-imgix-urls)
25
+ - [What is the `ixlib` param on every request?](#what-is-the-ixlib-param-on-every-request)
26
+ - [Contributing](#contributing)
6
27
 
7
28
  ## Installation
8
29
 
@@ -23,12 +44,12 @@ Or install it yourself as:
23
44
 
24
45
  ## Usage
25
46
 
26
- Initialize a client with a `:host` and your `:secure_url_token`. By default, HTTPS URLs are generated, but you can toggle that by passing `use_https: false`.
47
+ Initialize a client with a `:domain` and your `:secure_url_token`. By default, HTTPS URLs are generated, but you can toggle that by passing `use_https: false`.
27
48
 
28
49
  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
50
 
30
51
  ``` ruby
31
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
52
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
32
53
 
33
54
  client.path('/images/demo.png').to_url(w: 200)
34
55
  #=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
@@ -46,12 +67,23 @@ path.defaults.width(300).to_url # Resets parameters
46
67
  path.rect(x: 0, y: 50, width: 200, height: 300).to_url # Rect helper
47
68
  ```
48
69
 
70
+ **Deprecation Notice:** Usage of `:host` has been deprecated and will become invalid in the next major release.
71
+
72
+ In the previous version, `:host` can be used to specify a domain for an `Imgix::Client` like so:
73
+
74
+ ```ruby
75
+ Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: 'token')
76
+ ```
77
+
78
+ Code using `:host` like the above will continue to work until the next major release. While using `:host` will remain valid until the next major release, its usage will result in a deprecation warning. In order to resolve these deprecation warnings before upgrading to the new release, use `:domain` instead of `:host`.
79
+
80
+
49
81
  ## Srcset Generation
50
82
 
51
83
  The imgix gem allows for generation of custom `srcset` attributes, which can be invoked through `Imgix::Path#to_srcset`. By default, the `srcset` generated will allow for responsive size switching by building a list of image-width mappings.
52
84
 
53
85
  ```rb
54
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
86
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
55
87
  path = client.path('/images/demo.png')
56
88
 
57
89
  srcset = path.to_srcset
@@ -73,7 +105,7 @@ https://your-subdomain.imgix.net/images/demo.png?w=8192&s=9fbd257c53e770e345ce34
73
105
  In cases where enough information is provided about an image's dimensions, `to_srcset` will instead build a `srcset` that will allow for an image to be served at different resolutions. The parameters taken into consideration when determining if an image is fixed-width are `w`, `h`, and `ar`. By invoking `to_srcset` with either a width **or** the height and aspect ratio (along with `fit=crop`, typically) provided, a different `srcset` will be generated for a fixed-size image instead.
74
106
 
75
107
  ```rb
76
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
108
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
77
109
  path = client.path('/images/demo.png')
78
110
 
79
111
  srcset = path.to_srcset(h:800, ar:'3:2', fit:'crop')
@@ -96,7 +128,7 @@ For more information to better understand `srcset`, we highly recommend [Eric Po
96
128
  In situations where specific widths are desired when generating `srcset` pairs, a user can specify them by passing an array of integers via `widths` to the `options` keyword argument.
97
129
 
98
130
  ```rb
99
- @client ||= Imgix::Client.new(host: 'testing.imgix.net', include_library_param: false)
131
+ @client ||= Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
100
132
  .path('image.jpg')
101
133
  .to_srcset(options: { widths: [100, 500, 1000, 1800] })
102
134
  ```
@@ -119,7 +151,7 @@ The `srcset` width tolerance dictates the maximum tolerated size difference betw
119
151
  By default this rate is set to 8 percent, which we consider to be the ideal rate for maximizing cache hits without sacrificing visual quality. Users can specify their own width tolerance by passing a positive numeric value to `width_tolerance` within the `options` keyword argument:
120
152
 
121
153
  ```rb
122
- client = Imgix::Client.new(host: 'testing.imgix.net', secure_url_token: 'MYT0KEN', include_library_param: false)
154
+ client = Imgix::Client.new(domain: 'testing.imgix.net', secure_url_token: 'MYT0KEN', include_library_param: false)
123
155
  client.path('image.jpg').to_srcset(options: { width_tolerance: 0.20 })
124
156
  ```
125
157
 
@@ -138,7 +170,7 @@ https://testing.imgix.net/image.jpg?w=8192 8192w
138
170
  If the exact number of minimum/maximum physical pixels that an image will need to be rendered at is known, a user can specify them by passing an integer via `min_srcset` and/or `max_srcset` to the `options` keyword parameters:
139
171
 
140
172
  ```rb
141
- client = Imgix::Client.new(host: 'testing.imgix.net', include_library_param: false)
173
+ client = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
142
174
  client.path('image.jpg').to_srcset(options: { min_srcset: 500, max_srcset: 2000 })
143
175
  ```
144
176
 
@@ -171,7 +203,7 @@ This behavior will respect any overriding `q` value passed in as a parameter. Ad
171
203
  This behavior specifically occurs when a [fixed-size image](https://github.com/imgix/imgix-rb#fixed-image-rendering) is rendered, for example:
172
204
 
173
205
  ```rb
174
- srcset = Imgix::Client.new(host: 'testing.imgix.net', include_library_param: false)
206
+ srcset = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
175
207
  .path('image.jpg')
176
208
  .to_srcset(w:100)
177
209
  ```
@@ -201,15 +233,15 @@ path.noise_reduction(50,50)
201
233
  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.
202
234
 
203
235
  ```ruby
204
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', api_key: 'your-key')
236
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', api_key: 'your-key')
205
237
  client.purge('/images/demo.png')
206
238
  ```
207
239
 
208
240
  To learn more about purging assets with imgix, [see our docs](https://docs.imgix.com/setup/purging-images).
209
241
 
210
- ## URL encoding and signed ImgIX URLs
242
+ ## URL encoding and signed imgix URLs
211
243
 
212
- 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.
244
+ 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.
213
245
 
214
246
  ## What is the `ixlib` param on every request?
215
247
 
@@ -218,7 +250,7 @@ For security and diagnostic purposes, we sign all requests with the language and
218
250
  This can be disabled by including `include_library_param: false` in the instantiation Hash parameter for `Imgix::Client`:
219
251
 
220
252
  ```ruby
221
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', include_library_param: false )
253
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', include_library_param: false )
222
254
  ```
223
255
 
224
256
  ## Contributing
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.metadata = {
17
17
  'bug_tracker_uri' => 'https://github.com/imgix/imgix-rb/issues',
18
- 'changelog_uri' => 'https://github.com/imgix/imgix-rb/blob/master/CHANGELOG.md',
18
+ 'changelog_uri' => 'https://github.com/imgix/imgix-rb/blob/main/CHANGELOG.md',
19
19
  'documentation_uri' => "https://www.rubydoc.info/gems/imgix/#{spec.version}",
20
20
  'source_code_uri' => "https://github.com/imgix/imgix-rb/tree/#{spec.version}"
21
21
  }
@@ -6,7 +6,7 @@ require 'imgix/path'
6
6
 
7
7
  module Imgix
8
8
  # regex pattern used to determine if a domain is valid
9
- DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i
9
+ DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i.freeze
10
10
 
11
11
  # determines the growth rate when building out srcset pair widths
12
12
  DEFAULT_WIDTH_TOLERANCE = 0.08
@@ -20,17 +20,19 @@ module Imgix
20
20
  # returns an array of width values used during scrset generation
21
21
  TARGET_WIDTHS = lambda { |tolerance, min, max|
22
22
  increment_percentage = tolerance || DEFAULT_WIDTH_TOLERANCE
23
- unless increment_percentage.is_a? Numeric and increment_percentage > 0
24
- raise ArgumentError, "The width_tolerance argument must be passed a positive scalar value"
23
+
24
+ unless increment_percentage.is_a?(Numeric) && increment_percentage > 0
25
+ width_increment_error = 'error: `width_tolerance` must be a positive `Numeric` value'
26
+ raise ArgumentError, width_increment_error
25
27
  end
26
28
 
27
29
  max_size = max || MAX_WIDTH
28
30
  resolutions = []
29
31
  prev = min || MIN_WIDTH
30
32
 
31
- while(prev < max_size)
33
+ while prev < max_size
32
34
  # ensures that each width is even
33
- resolutions.push((2 * (prev / 2).round))
35
+ resolutions.push(prev.round)
34
36
  prev *= 1 + (increment_percentage * 2)
35
37
  end
36
38
 
@@ -40,10 +42,10 @@ module Imgix
40
42
 
41
43
  # hash of default quality parameter values mapped by each dpr srcset entry
42
44
  DPR_QUALITY = {
43
- 1 => 75,
45
+ 1 => 75,
44
46
  2 => 50,
45
47
  3 => 35,
46
48
  4 => 23,
47
49
  5 => 20
48
- }
50
+ }.freeze
49
51
  end
@@ -7,54 +7,84 @@ require 'uri'
7
7
 
8
8
  module Imgix
9
9
  class Client
10
- DEFAULTS = { use_https: true }
10
+ DEFAULTS = { use_https: true }.freeze
11
11
 
12
12
  def initialize(options = {})
13
13
  options = DEFAULTS.merge(options)
14
+ host, domain = options[:host], options[:domain]
15
+
16
+ host_deprecated = "Warning: The identifier `host' has been deprecated and " \
17
+ "will\nappear as `domain' in the next major version, e.g. " \
18
+ "`@host'\nbecomes `@domain', `options[:host]' becomes " \
19
+ "`options[:domain]'.\n"
20
+
21
+ if host
22
+ warn host_deprecated
23
+ @host = host
24
+ elsif domain
25
+ @host = domain
26
+ end
14
27
 
15
- @host = options[:host]
16
28
  validate_host!
29
+
17
30
  @secure_url_token = options[:secure_url_token]
18
31
  @api_key = options[:api_key]
19
32
  @use_https = options[:use_https]
20
33
  @include_library_param = options.fetch(:include_library_param, true)
21
- @library = options.fetch(:library_param, "rb")
34
+ @library = options.fetch(:library_param, 'rb')
22
35
  @version = options.fetch(:library_version, Imgix::VERSION)
23
36
  end
24
37
 
25
38
  def path(path)
26
- p = Path.new(prefix(path), @secure_url_token, path)
39
+ p = Path.new(new_prefix, @secure_url_token, path)
27
40
  p.ixlib("#{@library}-#{@version}") if @include_library_param
28
41
  p
29
42
  end
30
43
 
31
44
  def purge(path)
32
- raise "Authentication token required" unless !!(@api_key)
33
- url = prefix(path)+path
45
+ token_error = 'Authentication token required'
46
+ raise token_error if @api_key.nil?
47
+
48
+ url = new_prefix + path
34
49
  uri = URI.parse('https://api.imgix.com/v2/image/purger')
35
- req = Net::HTTP::Post.new(uri.path, {"User-Agent" => "imgix #{@library}-#{@version}"})
50
+
51
+ user_agent = { 'User-Agent' => "imgix #{@library}-#{@version}" }
52
+
53
+ req = Net::HTTP::Post.new(uri.path, user_agent)
36
54
  req.basic_auth @api_key, ''
37
- req.set_form_data({'url' => url})
55
+ req.set_form_data({ url: url })
56
+
38
57
  sock = Net::HTTP.new(uri.host, uri.port)
39
58
  sock.use_ssl = true
40
- res = sock.start {|http| http.request(req) }
59
+ res = sock.start { |http| http.request(req) }
60
+
41
61
  res
42
62
  end
43
63
 
44
64
  def prefix(path)
65
+ msg = "Warning: `Client::prefix' will take zero arguments " \
66
+ "in the next major version.\n"
67
+ warn msg
68
+ new_prefix
69
+ end
70
+
71
+ def new_prefix
45
72
  "#{@use_https ? 'https' : 'http'}://#{@host}"
46
73
  end
47
74
 
48
75
  private
49
76
 
50
77
  def validate_host!
51
- unless @host != nil
52
- raise ArgumentError, "The :host option must be specified"
53
- end
54
- if @host.match(DOMAIN_REGEX) == nil
55
- raise ArgumentError, "Domains must be passed in as fully-qualified domain names and should not include a protocol or any path element, i.e. \"example.imgix.net\"."
78
+ host_error = 'The :host option must be specified'
79
+ raise ArgumentError, host_error if @host.nil?
80
+
81
+ domain_error = 'Domains must be passed in as fully-qualified'\
82
+ 'domain names and should not include a protocol'\
83
+ 'or any path element, i.e. "example.imgix.net"'\
84
+
85
+ if @host.match(DOMAIN_REGEX).nil?
86
+ raise ArgumentError, domain_error
56
87
  end
57
88
  end
58
-
59
89
  end
60
90
  end