resizing 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile +2 -2
- data/README.md +59 -32
- data/lib/resizing/active_storage/service/resizing_service.rb +4 -2
- data/lib/resizing/carrier_wave/storage/file.rb +9 -1
- data/lib/resizing/carrier_wave.rb +5 -8
- data/lib/resizing/client.rb +22 -23
- data/lib/resizing/configurable.rb +1 -1
- data/lib/resizing/configuration.rb +6 -16
- data/lib/resizing/http_clientable.rb +3 -3
- data/lib/resizing/mock_client.rb +6 -5
- data/lib/resizing/public_id.rb +5 -4
- data/lib/resizing/version.rb +1 -1
- data/lib/resizing.rb +14 -12
- data/resizing.gemspec +3 -5
- data/test/resizing/carrier_wave_test.rb +53 -26
- data/test/resizing/client_test.rb +68 -12
- data/test/resizing/configuration_test.rb +2 -3
- data/test/resizing/error_test.rb +9 -9
- data/test/resizing/http_clientable_test.rb +1 -1
- data/test/resizing/public_id_test.rb +1 -1
- data/test/resizing_module_test.rb +88 -6
- data/test/test_helper.rb +87 -9
- metadata +13 -16
- /data/{exe → bin}/console +0 -0
- /data/{exe → bin}/generate-changelog +0 -0
- /data/{exe → bin}/setup +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5da346f4f6420f1f586bc20af1e983e7dfa3d2c12a452a8a3493efff172b2cb6
|
|
4
|
+
data.tar.gz: 5e37eb4217eb0b71562fa49f8e4c5bcb9392b84d589bf0e88b6507a437208778
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: becfa5580edcf664eef716cb15e2e511872ef1360e81b8218e296ac14f031b05cb3bc2b70d6876247baaedc8cf03571cd8987c8149af15bd7e3e8441ca17040c
|
|
7
|
+
data.tar.gz: fb7c57ece63ce14d5fe33f8a8e0e479e68becea5edd9e23b17a4a28cbe618183bc6a4d9c442dfdbd8da5cb04e570adb8c25362c6e24ad83e22487d1ba5cacecb
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# Resizing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://rubygems.org/gems/resizing)
|
|
4
|
+
[](https://github.com/jksy/resizing-gem/actions/workflows/test.yml)
|
|
5
|
+
[](https://codecov.io/gh/jksy/resizing-gem)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
Client and utilities for [Resizing](https://www.resizing.net/) - an image hosting and transformation service.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Ruby 3.1.0 or later
|
|
6
12
|
|
|
7
13
|
## Installation
|
|
8
14
|
|
|
@@ -20,37 +26,59 @@ Or install it yourself as:
|
|
|
20
26
|
|
|
21
27
|
$ gem install resizing
|
|
22
28
|
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
Resizing.configure = {
|
|
33
|
+
image_host: 'https://img.resizing.net',
|
|
34
|
+
video_host: 'https://video.resizing.net',
|
|
35
|
+
project_id: 'your-project-id',
|
|
36
|
+
secret_token: 'your-secret-token'
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
23
40
|
## Usage
|
|
24
41
|
|
|
42
|
+
### Basic Client Usage
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
# Initialize client
|
|
46
|
+
client = Resizing::Client.new
|
|
47
|
+
|
|
48
|
+
# Upload image to resizing
|
|
49
|
+
file = File.open('sample.jpg', 'r')
|
|
50
|
+
response = client.post(file)
|
|
51
|
+
# => {
|
|
52
|
+
# "id"=>"a4ed2bf0-a4cf-44fa-9c82-b53e581cb469",
|
|
53
|
+
# "project_id"=>"098a2a0d-0000-0000-0000-000000000000",
|
|
54
|
+
# "content_type"=>"image/jpeg",
|
|
55
|
+
# "latest_version_id"=>"LJY5bxBF7Ryxfr5kC1F.63W8bzp3pcUm",
|
|
56
|
+
# "latest_etag"=>"\"190143614e6c342637584f46f18f8c58\"",
|
|
57
|
+
# "created_at"=>"2020-05-15T15:33:10.711Z",
|
|
58
|
+
# "updated_at"=>"2020-05-15T15:33:10.711Z",
|
|
59
|
+
# "url"=>"/projects/098a2a0d-0000-0000-0000-000000000000/upload/images/a4ed2bf0-a4cf-44fa-9c82-b53e581cb469"
|
|
60
|
+
# }
|
|
61
|
+
|
|
62
|
+
# Generate transformation URL
|
|
63
|
+
image_id = response['id']
|
|
64
|
+
transformation_url = Resizing.url_from_image_id(image_id, nil, ['w_200', 'h_300'])
|
|
65
|
+
# => "https://img.resizing.net/projects/.../upload/images/.../w_200,h_300"
|
|
25
66
|
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"latest_etag"=>"\"190143614e6c342637584f46f18f8c58\"",
|
|
42
|
-
"created_at"=>"2020-05-15T15:33:10.711Z",
|
|
43
|
-
"updated_at"=>"2020-05-15T15:33:10.711Z",
|
|
44
|
-
"url"=>"/projects/098a2a0d-0000-0000-0000-000000000000/upload/images/a4ed2bf0-a4cf-44fa-9c82-b53e581cb469"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
name = response['url']
|
|
48
|
-
# get transformation url
|
|
49
|
-
name = response['url']
|
|
50
|
-
transform = {width: 200, height: 300}
|
|
51
|
-
|
|
52
|
-
transformation_url = Resizing.url(name, transform)
|
|
53
|
-
=> "https://www.resizing.net/projects/098a2a0d-0000-0000-0000-000000000000/upload/images/a4ed2bf0-a4cf-44fa-9c82-b53e581cb469/width_200,height_300"
|
|
67
|
+
|
|
68
|
+
### CarrierWave Integration
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
|
72
|
+
include Resizing::CarrierWave
|
|
73
|
+
|
|
74
|
+
version :list_smallest do
|
|
75
|
+
process resize_to_fill: [200, 200]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class User
|
|
80
|
+
mount_uploader :image, ImageUploader
|
|
81
|
+
end
|
|
54
82
|
```
|
|
55
83
|
|
|
56
84
|
## Development
|
|
@@ -61,8 +89,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
61
89
|
|
|
62
90
|
## Contributing
|
|
63
91
|
|
|
64
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/jksy/resizing.
|
|
65
|
-
|
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jksy/resizing-gem.
|
|
66
93
|
|
|
67
94
|
## License
|
|
68
95
|
|
|
@@ -8,10 +8,12 @@ module Resizing
|
|
|
8
8
|
# ref.
|
|
9
9
|
# https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/service/s3_service.rb
|
|
10
10
|
#
|
|
11
|
-
# rubocop:disable
|
|
11
|
+
# rubocop:disable Metrics/ParameterLists
|
|
12
12
|
class ResizingService < ::ActiveStorage::Service
|
|
13
13
|
# def initialize(bucket:, upload: {}, public: false, **options)
|
|
14
|
+
# rubocop:disable Lint/MissingSuper
|
|
14
15
|
def initialize; end
|
|
16
|
+
# rubocop:enable Lint/MissingSuper
|
|
15
17
|
|
|
16
18
|
def upload(_key, _io, checksum: nil, filename: nil, content_type: nil, disposition: nil, **)
|
|
17
19
|
raise NotImplementedError, 'upload is not implemented'
|
|
@@ -53,7 +55,7 @@ module Resizing
|
|
|
53
55
|
raise NotImplementedError, 'public_url is not implemented'
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
|
-
# rubocop:enable
|
|
58
|
+
# rubocop:enable Metrics/ParameterLists
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module Resizing
|
|
4
4
|
module CarrierWave
|
|
5
5
|
module Storage
|
|
6
|
+
# rubocop:disable Metrics/ClassLength
|
|
6
7
|
class File
|
|
7
8
|
include ::CarrierWave::Utilities::Uri
|
|
8
9
|
|
|
@@ -28,6 +29,7 @@ module Resizing
|
|
|
28
29
|
@content_type || file.try(:content_type)
|
|
29
30
|
end
|
|
30
31
|
|
|
32
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
31
33
|
def delete
|
|
32
34
|
# Use the identifier from constructor if available, otherwise try to get from model
|
|
33
35
|
if @public_id.present?
|
|
@@ -58,6 +60,7 @@ module Resizing
|
|
|
58
60
|
|
|
59
61
|
raise APIError, "raise someone error:#{resp.inspect}"
|
|
60
62
|
end
|
|
63
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
61
64
|
|
|
62
65
|
def extension
|
|
63
66
|
raise NotImplementedError, 'this method is do not used. maybe'
|
|
@@ -96,6 +99,8 @@ module Resizing
|
|
|
96
99
|
end
|
|
97
100
|
alias path current_path
|
|
98
101
|
|
|
102
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
103
|
+
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
99
104
|
def store(new_file)
|
|
100
105
|
if new_file.is_a?(self.class)
|
|
101
106
|
# new_file.copy_to(path)
|
|
@@ -136,8 +141,10 @@ module Resizing
|
|
|
136
141
|
|
|
137
142
|
true
|
|
138
143
|
end
|
|
144
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
145
|
+
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
139
146
|
|
|
140
|
-
def name(
|
|
147
|
+
def name(_options = {})
|
|
141
148
|
@public_id = PublicId.new(model.send(:read_attribute, serialization_column))
|
|
142
149
|
CGI.unescape(@public_id.filename)
|
|
143
150
|
end
|
|
@@ -222,6 +229,7 @@ module Resizing
|
|
|
222
229
|
# "Need to implement #clean_cache! if you want to use #{self.class.name} as a cache storage."
|
|
223
230
|
# end
|
|
224
231
|
end
|
|
232
|
+
# rubocop:enable Metrics/ClassLength
|
|
225
233
|
end
|
|
226
234
|
end
|
|
227
235
|
end
|
|
@@ -4,6 +4,7 @@ require 'resizing/carrier_wave/storage/file'
|
|
|
4
4
|
require 'resizing/carrier_wave/storage/remote'
|
|
5
5
|
|
|
6
6
|
module Resizing
|
|
7
|
+
# rubocop:disable Metrics/ModuleLength
|
|
7
8
|
module CarrierWave
|
|
8
9
|
class Railtie < ::Rails::Railtie
|
|
9
10
|
# Railtie skelton codes
|
|
@@ -46,7 +47,7 @@ module Resizing
|
|
|
46
47
|
|
|
47
48
|
transforms = args.map do |version|
|
|
48
49
|
version = version.intern
|
|
49
|
-
raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.
|
|
50
|
+
raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.key? version
|
|
50
51
|
|
|
51
52
|
versions[version].transform_string
|
|
52
53
|
end.compact
|
|
@@ -110,11 +111,6 @@ module Resizing
|
|
|
110
111
|
read_column
|
|
111
112
|
end
|
|
112
113
|
|
|
113
|
-
def store!
|
|
114
|
-
# DO NOTHING
|
|
115
|
-
super
|
|
116
|
-
end
|
|
117
|
-
|
|
118
114
|
def serialization_column
|
|
119
115
|
model.send(:_mounter, mounted_as).send(:serialization_column)
|
|
120
116
|
end
|
|
@@ -152,7 +148,7 @@ module Resizing
|
|
|
152
148
|
|
|
153
149
|
private
|
|
154
150
|
|
|
155
|
-
# rubocop:disable Metrics/AbcSize
|
|
151
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
156
152
|
def transform_string_from(processor)
|
|
157
153
|
action = processor.first
|
|
158
154
|
value = processor.second
|
|
@@ -175,6 +171,7 @@ module Resizing
|
|
|
175
171
|
"#{key}_#{value}"
|
|
176
172
|
end.compact.join(',')
|
|
177
173
|
end
|
|
178
|
-
# rubocop:enable Metrics/AbcSize
|
|
174
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
179
175
|
end
|
|
176
|
+
# rubocop:enable Metrics/ModuleLength
|
|
180
177
|
end
|
data/lib/resizing/client.rb
CHANGED
|
@@ -24,6 +24,7 @@ module Resizing
|
|
|
24
24
|
# }
|
|
25
25
|
#
|
|
26
26
|
#++
|
|
27
|
+
# rubocop:disable Metrics/ClassLength
|
|
27
28
|
class Client
|
|
28
29
|
include Resizing::Constants
|
|
29
30
|
include Resizing::Configurable
|
|
@@ -53,8 +54,7 @@ module Resizing
|
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
result
|
|
57
|
+
handle_create_response(response)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def put(image_id, filename_or_io, options)
|
|
@@ -73,8 +73,7 @@ module Resizing
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
result
|
|
76
|
+
handle_create_response(response)
|
|
78
77
|
end
|
|
79
78
|
|
|
80
79
|
def delete(image_id)
|
|
@@ -86,8 +85,7 @@ module Resizing
|
|
|
86
85
|
end
|
|
87
86
|
end
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
result
|
|
88
|
+
handle_delete_response(response)
|
|
91
89
|
end
|
|
92
90
|
|
|
93
91
|
def metadata(image_id, options = {})
|
|
@@ -99,8 +97,7 @@ module Resizing
|
|
|
99
97
|
end
|
|
100
98
|
end
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
result
|
|
100
|
+
handle_metadata_response(response, options)
|
|
104
101
|
end
|
|
105
102
|
|
|
106
103
|
private
|
|
@@ -114,8 +111,7 @@ module Resizing
|
|
|
114
111
|
end
|
|
115
112
|
|
|
116
113
|
def gather_filename(filename_or_io, options)
|
|
117
|
-
|
|
118
|
-
filename ||= filename_or_io.respond_to?(:path) ? File.basename(filename_or_io.path) : nil
|
|
114
|
+
options[:filename] || (filename_or_io.respond_to?(:path) ? File.basename(filename_or_io.path) : nil)
|
|
119
115
|
end
|
|
120
116
|
|
|
121
117
|
def build_put_url(image_id)
|
|
@@ -140,17 +136,14 @@ module Resizing
|
|
|
140
136
|
# Accept IO-like objects (StringIO, Tempfile, etc.)
|
|
141
137
|
return if filename_or_io.respond_to?(:read) && filename_or_io.respond_to?(:rewind)
|
|
142
138
|
|
|
143
|
-
if filename_or_io.is_a?(String)
|
|
144
|
-
if File.exist?(filename_or_io)
|
|
145
|
-
return
|
|
146
|
-
end
|
|
147
|
-
end
|
|
139
|
+
return if filename_or_io.is_a?(String) && File.exist?(filename_or_io)
|
|
148
140
|
|
|
149
|
-
raise ArgumentError,
|
|
141
|
+
raise ArgumentError,
|
|
142
|
+
"filename_or_io must be a File object, an IO-like object, or a path to a file (#{filename_or_io.class})"
|
|
150
143
|
end
|
|
151
144
|
|
|
152
145
|
def handle_create_response(response)
|
|
153
|
-
raise APIError,
|
|
146
|
+
raise APIError, 'No response is returned' if response.nil?
|
|
154
147
|
|
|
155
148
|
case response.status
|
|
156
149
|
when HTTP_STATUS_OK, HTTP_STATUS_CREATED
|
|
@@ -161,7 +154,7 @@ module Resizing
|
|
|
161
154
|
end
|
|
162
155
|
|
|
163
156
|
def handle_delete_response(response)
|
|
164
|
-
raise APIError,
|
|
157
|
+
raise APIError, 'No response is returned' if response.nil?
|
|
165
158
|
|
|
166
159
|
case response.status
|
|
167
160
|
when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
|
|
@@ -174,24 +167,30 @@ module Resizing
|
|
|
174
167
|
def handle_metadata_response(response, options = {})
|
|
175
168
|
when_not_found = options[:when_not_found] || nil
|
|
176
169
|
|
|
177
|
-
raise APIError,
|
|
170
|
+
raise APIError, 'No response is returned' if response.nil?
|
|
178
171
|
|
|
179
172
|
case response.status
|
|
180
|
-
when HTTP_STATUS_OK
|
|
173
|
+
when HTTP_STATUS_OK
|
|
181
174
|
JSON.parse(response.body)
|
|
182
175
|
when HTTP_STATUS_NOT_FOUND
|
|
183
176
|
raise decode_error_from(response) if when_not_found == :raise
|
|
184
|
-
|
|
177
|
+
|
|
178
|
+
JSON.parse(response.body)
|
|
185
179
|
else
|
|
186
180
|
raise decode_error_from(response)
|
|
187
181
|
end
|
|
188
182
|
end
|
|
189
183
|
|
|
190
|
-
def decode_error_from
|
|
191
|
-
result =
|
|
184
|
+
def decode_error_from(response)
|
|
185
|
+
result = begin
|
|
186
|
+
JSON.parse(response.body)
|
|
187
|
+
rescue StandardError
|
|
188
|
+
{}
|
|
189
|
+
end
|
|
192
190
|
err = APIError.new(result['message'] || "invalid http status code #{response.status}")
|
|
193
191
|
err.decoded_body = result
|
|
194
192
|
err
|
|
195
193
|
end
|
|
196
194
|
end
|
|
195
|
+
# rubocop:enable Metrics/ClassLength
|
|
197
196
|
end
|
|
@@ -27,12 +27,8 @@ module Resizing
|
|
|
27
27
|
def initialize(*attrs)
|
|
28
28
|
case attr = attrs.first
|
|
29
29
|
when Hash
|
|
30
|
-
if attr[:project_id].nil? || attr[:secret_token].nil?
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
if attr[:host].present?
|
|
34
|
-
raise_configiration_error
|
|
35
|
-
end
|
|
30
|
+
raise_configiration_error if attr[:project_id].nil? || attr[:secret_token].nil?
|
|
31
|
+
raise_configiration_error if attr[:host].present?
|
|
36
32
|
|
|
37
33
|
initialize_by_hash attr
|
|
38
34
|
return
|
|
@@ -41,11 +37,6 @@ module Resizing
|
|
|
41
37
|
raise_configiration_error
|
|
42
38
|
end
|
|
43
39
|
|
|
44
|
-
def host
|
|
45
|
-
Kernel.warn "[DEPRECATED] The Configuration#host is deprecated. Use Configuration#image_host."
|
|
46
|
-
self.image_host
|
|
47
|
-
end
|
|
48
|
-
|
|
49
40
|
def generate_auth_header
|
|
50
41
|
current_timestamp = Time.now.to_i
|
|
51
42
|
data = [current_timestamp, secret_token].join('|')
|
|
@@ -102,13 +93,11 @@ module Resizing
|
|
|
102
93
|
raise ConfigurationError, 'need hash and some keys like :image_host, video_host, :project_id, :secret_token'
|
|
103
94
|
end
|
|
104
95
|
|
|
96
|
+
# rubocop:disable Metrics/AbcSize
|
|
105
97
|
def initialize_by_hash(attr)
|
|
106
|
-
|
|
107
|
-
if attr[:host].present?
|
|
108
|
-
Kernel.warn "[DEPRECATED] The host on configration is deprecated. Use image_host, video_host" if attr[:host].present?
|
|
109
|
-
@image_host ||= attr[:host].dup.freeze || DEFAULT_HOST # for backward compatible
|
|
110
|
-
end
|
|
98
|
+
raise 'The host on configuration is deprecated. Use image_host, video_host' if attr[:host].present?
|
|
111
99
|
|
|
100
|
+
@image_host = attr[:image_host].dup.freeze || DEFAULT_IMAGE_HOST
|
|
112
101
|
@video_host = attr[:video_host].dup.freeze || DEFAULT_VIDEO_HOST
|
|
113
102
|
@project_id = attr[:project_id].dup.freeze
|
|
114
103
|
@secret_token = attr[:secret_token].dup.freeze
|
|
@@ -116,5 +105,6 @@ module Resizing
|
|
|
116
105
|
@response_timeout = attr[:response_timeout] || DEFAULT_RESPONSE_TIMEOUT
|
|
117
106
|
@enable_mock = attr[:enable_mock] || false
|
|
118
107
|
end
|
|
108
|
+
# rubocop:enable Metrics/AbcSize
|
|
119
109
|
end
|
|
120
110
|
end
|
|
@@ -12,14 +12,14 @@ module Resizing
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def handle_faraday_error
|
|
15
|
+
def handle_faraday_error
|
|
16
16
|
yield
|
|
17
17
|
rescue Faraday::TimeoutError => e
|
|
18
18
|
handle_timeout_error e
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def handle_timeout_error
|
|
22
|
-
raise APIError
|
|
21
|
+
def handle_timeout_error(error)
|
|
22
|
+
raise APIError, "TimeoutError: #{error.inspect}"
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
data/lib/resizing/mock_client.rb
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Resizing
|
|
4
4
|
class MockClient
|
|
5
|
-
def post(
|
|
5
|
+
def post(_file_or_binary, _options = {})
|
|
6
6
|
r = load_yaml('test/vcr/client/post.yml')
|
|
7
7
|
JSON.parse(r['string'])
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def put(name,
|
|
10
|
+
def put(name, _file_or_binary, _options)
|
|
11
11
|
r = load_yaml('test/vcr/client/put.yml')
|
|
12
12
|
result = JSON.parse(r['string'])
|
|
13
13
|
# replace name, public_id and version by name argument
|
|
@@ -26,7 +26,7 @@ module Resizing
|
|
|
26
26
|
result
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def metadata(name)
|
|
29
|
+
def metadata(name, _options = {})
|
|
30
30
|
r = load_yaml('test/vcr/client/metadata.yml')
|
|
31
31
|
result = JSON.parse(r['string'])
|
|
32
32
|
# replace name and public_id by name argument
|
|
@@ -34,15 +34,16 @@ module Resizing
|
|
|
34
34
|
result['public_id'].gsub!(/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/, name)
|
|
35
35
|
result
|
|
36
36
|
end
|
|
37
|
+
|
|
37
38
|
private
|
|
38
39
|
|
|
39
|
-
def load_yaml
|
|
40
|
+
def load_yaml(filename)
|
|
40
41
|
path = "#{library_root}/#{filename}"
|
|
41
42
|
YAML.load_file(path)['http_interactions'].first['response']['body']
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def library_root
|
|
45
|
-
@library_root ||= File.expand_path('
|
|
46
|
+
@library_root ||= File.expand_path('../..', __dir__)
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
49
|
end
|
data/lib/resizing/public_id.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Resizing
|
|
2
4
|
class PublicId
|
|
3
|
-
def initialize
|
|
5
|
+
def initialize(public_id)
|
|
4
6
|
@public_id = public_id
|
|
5
7
|
parsed
|
|
6
8
|
end
|
|
@@ -38,13 +40,12 @@ module Resizing
|
|
|
38
40
|
|
|
39
41
|
def parsed
|
|
40
42
|
return nil if @public_id.nil?
|
|
43
|
+
|
|
41
44
|
unless defined? @parsed
|
|
42
45
|
@parsed = Resizing.separate_public_id(@public_id)
|
|
43
|
-
raise "type error #{@public_id}" if @parsed
|
|
46
|
+
raise "type error #{@public_id}" if @parsed.nil?
|
|
44
47
|
end
|
|
45
48
|
@parsed
|
|
46
49
|
end
|
|
47
|
-
|
|
48
|
-
private
|
|
49
50
|
end
|
|
50
51
|
end
|
data/lib/resizing/version.rb
CHANGED
data/lib/resizing.rb
CHANGED
|
@@ -19,13 +19,15 @@ module Resizing
|
|
|
19
19
|
|
|
20
20
|
class Error < StandardError; end
|
|
21
21
|
class ConfigurationError < Error; end
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
class APIError < Error
|
|
23
24
|
def decoded_body
|
|
24
25
|
@decoded_body ||= {}
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def decoded_body=(value)
|
|
28
29
|
raise ArgumentError, 'The decoded_body is expected to be passed a Hash.' unless value.is_a? Hash
|
|
30
|
+
|
|
29
31
|
@decoded_body = value
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -50,39 +52,39 @@ module Resizing
|
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def self.post(file_or_binary, options)
|
|
53
|
-
|
|
55
|
+
client.post file_or_binary, options
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def self.put(name, file_or_binary, options)
|
|
57
|
-
|
|
59
|
+
client.put name, file_or_binary, options
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
def self.delete(name)
|
|
61
|
-
|
|
63
|
+
client.delete name
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def self.metadata(name, options)
|
|
65
|
-
|
|
67
|
+
client.metadata name, options
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
# TODO: refactoring
|
|
69
71
|
#
|
|
70
72
|
# identifier:
|
|
71
|
-
# public_id: /projects
|
|
72
|
-
# identifier:
|
|
73
|
-
# project_id:
|
|
74
|
-
# image_id:
|
|
75
|
-
# version:
|
|
73
|
+
# public_id: /projects/<project_id>/upload/images/<image_id>/v<version>
|
|
74
|
+
# identifier: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
75
|
+
# project_id: ^^^^^^^^^^^^^
|
|
76
|
+
# image_id: ^^^^^^^^^^
|
|
77
|
+
# version: ^^^^^^^^
|
|
76
78
|
def self.generate_identifier
|
|
77
79
|
Resizing.configure.generate_identifier
|
|
78
80
|
end
|
|
79
81
|
|
|
80
|
-
def self.separate_public_id
|
|
82
|
+
def self.separate_public_id(public_id)
|
|
81
83
|
public_id.match('/projects/(?<project_id>[0-9a-f-]+)/upload/images/(?<image_id>[^/]+)(/v(?<version>[^/]+))?')
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def self.client
|
|
85
|
-
if
|
|
87
|
+
if configure.enable_mock
|
|
86
88
|
Resizing::MockClient.new
|
|
87
89
|
else
|
|
88
90
|
Resizing::Client.new
|
data/resizing.gemspec
CHANGED
|
@@ -25,8 +25,6 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
26
|
`git ls-files -z`.split("\x0")
|
|
27
27
|
end
|
|
28
|
-
spec.bindir = 'exe'
|
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
28
|
spec.require_paths = ['lib']
|
|
31
29
|
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
|
32
30
|
spec.add_development_dependency 'rails', ">= 6.0", '< 7.1'
|
|
@@ -34,10 +32,10 @@ Gem::Specification.new do |spec|
|
|
|
34
32
|
spec.add_development_dependency 'fog-aws'
|
|
35
33
|
spec.add_development_dependency 'minitest', '~> 5.16'
|
|
36
34
|
spec.add_development_dependency 'minitest-ci'
|
|
37
|
-
spec.add_development_dependency 'rubocop'
|
|
38
|
-
spec.add_development_dependency 'timecop'
|
|
39
|
-
spec.add_development_dependency 'vcr'
|
|
40
35
|
spec.add_development_dependency 'mysql2'
|
|
36
|
+
spec.add_development_dependency 'rubocop'
|
|
41
37
|
spec.add_development_dependency 'simplecov'
|
|
42
38
|
spec.add_development_dependency 'simplecov-cobertura'
|
|
39
|
+
spec.add_development_dependency 'timecop'
|
|
40
|
+
spec.add_development_dependency 'vcr'
|
|
43
41
|
end
|