cloudimage 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: 06d221bc041ab617d9997d66e6d2c4b9f03dcbdcbbf4c05cb6b54f1c66f7c5f1
4
- data.tar.gz: 2ed732e2099d6a3b1a9649da9840b303bef144f43b0cd2801e09f6d080361c28
3
+ metadata.gz: 72e83343c301b5b791cd7fa5f88593fd3715cfa01d918e6d473aae4376022594
4
+ data.tar.gz: '059edd8cd34c45bf7226cd876fb10d64d4cefc93059996d6e12f66a0ccc2d96d'
5
5
  SHA512:
6
- metadata.gz: 5385f01daa66e04d394c8cc2d0257f367ba5f18f3f553ccc71a7341c4149975c94a5b707305cf3e3a6c93a6ff5a2346a459c623d7ca80aff35ca65c886dd0cb9
7
- data.tar.gz: f4130b0bf5d7b40325e5a04f69a5e8dcbe117519369a517d4665788c3c78d0e84ba976d1c542bf0a06a38082893dd2342e695b8906e2ef9df54df0f807a389e9
6
+ metadata.gz: 24d09cd09df390e46f6e9e0035ae3df80eb458a2b80c7f6f39d922c21c333063e4abd95302f63a007dc6da289301875b3bd7ec87c2c21daa2d08dd96799d8b29
7
+ data.tar.gz: 805d1c5b001cebd0deaf230111785284c69e6759e3d64f18d635df832195495a19afa209a1c0fc45484b44dd7ead82edff532747cfec12a8d838851cfc7607fa
@@ -1,16 +1,18 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/scaleflex/cloudimage-rb/tree/HEAD)
3
+ ## [v0.3.0](https://github.com/scaleflex/cloudimage-rb/tree/v0.3.0) (2020-07-09)
4
4
 
5
- [Full Changelog](https://github.com/scaleflex/cloudimage-rb/compare/v0.2.1...HEAD)
5
+ [Full Changelog](https://github.com/scaleflex/cloudimage-rb/compare/v0.2.1...v0.3.0)
6
6
 
7
7
  **Closed issues:**
8
8
 
9
+ - Add URL sealing [\#12](https://github.com/scaleflex/cloudimage-rb/issues/12)
9
10
  - Add automatic changelog generation [\#11](https://github.com/scaleflex/cloudimage-rb/issues/11)
10
11
 
11
12
  **Merged pull requests:**
12
13
 
13
14
  - Use changelog generation [\#16](https://github.com/scaleflex/cloudimage-rb/pull/16) ([janklimo](https://github.com/janklimo))
15
+ - Introduce URL sealing [\#10](https://github.com/scaleflex/cloudimage-rb/pull/10) ([janklimo](https://github.com/janklimo))
14
16
  - Add test coverage with SimpleCov [\#9](https://github.com/scaleflex/cloudimage-rb/pull/9) ([janklimo](https://github.com/janklimo))
15
17
 
16
18
  ## 0.2.1 (2020-06-29)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # cloudimage
2
2
 
3
- ![](https://github.com/scaleflex/cloudimage-rb/workflows/Build/badge.svg)
3
+ [![Gem Version](https://badge.fury.io/rb/cloudimage.svg)](https://badge.fury.io/rb/cloudimage) ![Build status](https://github.com/scaleflex/cloudimage-rb/workflows/Build/badge.svg)
4
4
 
5
5
  `cloudimage` is the official Ruby API wrapper for
6
6
  [Cloudimage's API](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction).
@@ -12,15 +12,15 @@ Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
12
12
  - [Usage](#usage)
13
13
  - [Hash of params](#hash-of-params)
14
14
  - [Chainable helpers](#chainable-helpers)
15
- - [Aliases](#aliases)
15
+ - [Method aliases](#method-aliases)
16
16
  - [Custom helpers](#custom-helpers)
17
+ - [URL aliases](#url-aliases)
17
18
  - [Security](#security)
18
19
  - [URL signature](#url-signature)
19
20
  - [URL sealing](#url-sealing)
20
21
  - [Development](#development)
21
22
  - [Contributing](#contributing)
22
23
  - [License](#license)
23
- - [Code of Conduct](#code-of-conduct)
24
24
  - [Showcase](#showcase)
25
25
 
26
26
  ## Installation
@@ -55,13 +55,13 @@ client = Cloudimage::Client.new(token: 'mysecrettoken')
55
55
 
56
56
  Cloudimage client accepts the following options:
57
57
 
58
- | Option | Required? | Additional info |
59
- | ------------------ | --------- | --------------------------------------------------- |
60
- | `token` | Yes | |
61
- | `salt` | No | See [Security](#security). |
62
- | `signature_length` | No | Integer value in the range `6..40`. Defaults to 18. |
63
- | `api_version` | No | Defaults to the current stable version. |
64
- | `sign_urls` | No | Defaults to `true`. See [Security](#security). |
58
+ | Option | Required? | Type | Additional info |
59
+ | ------------------ | --------- | ------- | --------------------------------------------------- |
60
+ | `token` | Yes | string | |
61
+ | `salt` | No | string | See [Security](#security). |
62
+ | `signature_length` | No | integer | Integer value in the range `6..40`. Defaults to 18. |
63
+ | `sign_urls` | No | boolean | Defaults to `true`. See [Security](#security). |
64
+ | `aliases` | No | hash | See [URL aliases](#url-aliases). |
65
65
 
66
66
  Calling `path` on the client object returns an instance of `Cloudimage::URI`.
67
67
  It accepts path to the image as a string and we we will use it to build
@@ -104,7 +104,7 @@ uri.heigth(200).to_url
104
104
  This is useful for catching typos and identifying deprecated methods in
105
105
  case Cloudimage's API changes.
106
106
 
107
- ### Aliases
107
+ ### Method aliases
108
108
 
109
109
  The gem comes with a handful of useful aliases. Consult
110
110
  [`Cloudimage::Params`](lib/cloudimage/params.rb) module for their full list.
@@ -122,6 +122,29 @@ need to accept arguments and will be translated into `param=1` in the final URL.
122
122
  For a list of custom helpers available to you, please consult
123
123
  [`Cloudimage::CustomHelpers`](lib/cloudimage/custom_helpers.rb) module.
124
124
 
125
+ ### URL aliases
126
+
127
+ Specify [aliases](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/domains-urls/aliases)
128
+ to automatically replace parts of path with defined values. Aliases is a hash which
129
+ maps strings to be replaced with values to be used instead.
130
+
131
+ ```ruby
132
+ my_alias = 'https://store.s3-us-west-2.amazonaws.com/uploads'
133
+ client = Cloudimage::Client.new(token: 'token', aliases: { my_alias => '_uploads_' })
134
+ client.path('https://store.s3-us-west-2.amazonaws.com/uploads/image.jpg').to_url
135
+ # => "https://token.cloudimg.io/v7/_uploads_/image.jpg"
136
+ ```
137
+
138
+ [URL prefix](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/domains-urls/origin-url-prefix)
139
+ is just another form of URL alias. Simply make the target value an empty string:
140
+
141
+ ```ruby
142
+ prefix = 'https://store.s3-us-west-2.amazonaws.com/uploads/'
143
+ client = Cloudimage::Client.new(token: 'token', aliases: { prefix => '' })
144
+ client.path('https://store.s3-us-west-2.amazonaws.com/uploads/image.jpg').to_url
145
+ # => "https://token.cloudimg.io/v7/image.jpg"
146
+ ```
147
+
125
148
  ### Security
126
149
 
127
150
  #### URL signature
@@ -194,14 +217,7 @@ are expected to adhere to the
194
217
 
195
218
  ## License
196
219
 
197
- The gem is available as open source under the terms of the
198
- [MIT License](https://opensource.org/licenses/MIT).
199
-
200
- ## Code of Conduct
201
-
202
- Everyone interacting with the project's codebase, issues, and pull
203
- requests is expected to follow the
204
- [code of conduct](https://github.com/scaleflex/cloudimage-rb/blob/master/CODE_OF_CONDUCT.md).
220
+ [MIT](https://opensource.org/licenses/MIT)
205
221
 
206
222
  ## Showcase
207
223
 
@@ -2,5 +2,4 @@
2
2
 
3
3
  require 'addressable/uri'
4
4
 
5
- require_relative 'cloudimage/version'
6
5
  require_relative 'cloudimage/client'
@@ -19,6 +19,7 @@ module Cloudimage
19
19
  options[:signature_length] || DEFAULT_SIGNATURE_LENGTH
20
20
  @config[:api_version] = API_VERSION
21
21
  @config[:sign_urls] = options[:sign_urls].nil? ? true : false
22
+ @config[:aliases] = options[:aliases] || {}
22
23
 
23
24
  ensure_valid_config
24
25
  end
@@ -19,5 +19,29 @@ module Cloudimage
19
19
  end
20
20
  end
21
21
  end
22
+
23
+ unless Kernel.respond_to?(:yield_self)
24
+ refine Kernel do
25
+ def yield_self
26
+ unless block_given?
27
+ return ::Enumerator.new(1) do |yielder|
28
+ yielder.yield(self)
29
+ end
30
+ end
31
+
32
+ yield(self)
33
+ end
34
+ end
35
+ end
36
+
37
+ unless Kernel.respond_to?(:then)
38
+ refine Kernel do
39
+ def then
40
+ return yield_self unless block_given?
41
+
42
+ yield_self(&::Proc.new)
43
+ end
44
+ end
45
+ end
22
46
  end
23
47
  end
@@ -18,7 +18,7 @@ module Cloudimage
18
18
  @config = config
19
19
  @params = {}
20
20
  @sealed_params = Set.new
21
- @path = ensure_path_format(path)
21
+ @path = transform(path)
22
22
  @uri = build_uri
23
23
  end
24
24
 
@@ -50,8 +50,20 @@ module Cloudimage
50
50
  "/#{config[:api_version]}"
51
51
  end
52
52
 
53
- def ensure_path_format(path)
54
- path.start_with?('/') ? path : "/#{path}"
53
+ def transform(path)
54
+ path
55
+ .then { |input| input.start_with?('/') ? input : "/#{input}" }
56
+ .then(&method(:apply_aliases))
57
+ end
58
+
59
+ def apply_aliases(path)
60
+ return path if config[:aliases].empty?
61
+
62
+ path.dup.tap do |input|
63
+ config[:aliases].each do |source, target|
64
+ input.gsub!(source, target)
65
+ end
66
+ end
55
67
  end
56
68
 
57
69
  def request_uri
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Klimo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -72,7 +72,6 @@ files:
72
72
  - lib/cloudimage/refinements.rb
73
73
  - lib/cloudimage/security.rb
74
74
  - lib/cloudimage/uri.rb
75
- - lib/cloudimage/version.rb
76
75
  homepage: https://github.com/scaleflex/cloudimage-rb
77
76
  licenses:
78
77
  - MIT
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cloudimage
4
- VERSION = '0.3.0'
5
- end