resizing 1.0.0.pre → 1.0.1
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 +61 -0
- data/Gemfile +4 -0
- data/lib/resizing/active_storage/service/resizing_service.rb +2 -0
- data/lib/resizing/active_storage/service.rb +9 -0
- data/lib/resizing/active_storage.rb +7 -0
- data/lib/resizing/carrier_wave/storage/file.rb +26 -15
- data/lib/resizing/carrier_wave/storage/remote.rb +7 -3
- data/lib/resizing/carrier_wave.rb +5 -3
- data/lib/resizing/client.rb +23 -24
- data/lib/resizing/version.rb +1 -1
- data/lib/resizing.rb +2 -0
- data/resizing.gemspec +6 -3
- data/test/resizing/active_storage_service_test.rb +98 -0
- data/test/resizing/carrier_wave/storage/file_test.rb +149 -8
- data/test/resizing/carrier_wave/storage/remote_test.rb +75 -0
- data/test/resizing/carrier_wave_test.rb +63 -28
- data/test/resizing/client_test.rb +30 -1
- data/test/resizing/configurable_test.rb +82 -0
- data/test/resizing/configuration_test.rb +117 -0
- data/test/resizing/constants_test.rb +25 -0
- data/test/resizing/error_test.rb +73 -0
- data/test/resizing/http_clientable_test.rb +84 -0
- data/test/resizing/mock_client_test.rb +75 -0
- data/test/resizing_module_test.rb +124 -0
- data/test/test_helper.rb +20 -0
- metadata +73 -22
- data/.circleci/config.yml +0 -73
- data/lib/resizing/video/client.rb +0 -116
- data/lib/resizing/video.rb +0 -8
- data/test/resizing/video/client_test.rb +0 -158
- data/test/vcr/video/metadata/success.yml +0 -47
- data/test/vcr/video/prepare/success.yml +0 -47
- data/test/vcr/video/upload_completed/success.yml +0 -47
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
class MockClientTest < Minitest::Test
|
|
7
|
+
def setup
|
|
8
|
+
@client = Resizing::MockClient.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
# NOP
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_post_returns_parsed_json
|
|
16
|
+
VCR.use_cassette('client/post', record: :none) do
|
|
17
|
+
result = @client.post(nil)
|
|
18
|
+
|
|
19
|
+
assert_instance_of Hash, result
|
|
20
|
+
assert result.key?('id')
|
|
21
|
+
assert result.key?('public_id')
|
|
22
|
+
assert result.key?('latest_version_id')
|
|
23
|
+
assert result.key?('latest_etag')
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_put_returns_parsed_json_with_modified_name
|
|
28
|
+
VCR.use_cassette('client/put', record: :none) do
|
|
29
|
+
name = 'test-image-123'
|
|
30
|
+
result = @client.put(name, nil, {})
|
|
31
|
+
|
|
32
|
+
assert_instance_of Hash, result
|
|
33
|
+
assert_equal name, result['id']
|
|
34
|
+
assert_includes result['public_id'], name
|
|
35
|
+
assert result.key?('latest_version_id')
|
|
36
|
+
assert result.key?('latest_etag')
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_delete_returns_parsed_json_with_modified_name
|
|
41
|
+
VCR.use_cassette('client/delete', record: :none) do
|
|
42
|
+
name = 'delete-test-image'
|
|
43
|
+
result = @client.delete(name)
|
|
44
|
+
|
|
45
|
+
assert_instance_of Hash, result
|
|
46
|
+
assert_equal name, result['id']
|
|
47
|
+
assert_includes result['public_id'], name
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_metadata_returns_parsed_json_with_modified_name
|
|
52
|
+
VCR.use_cassette('client/metadata', record: :none) do
|
|
53
|
+
name = 'metadata-test-image'
|
|
54
|
+
result = @client.metadata(name)
|
|
55
|
+
|
|
56
|
+
assert_instance_of Hash, result
|
|
57
|
+
assert_equal name, result['id']
|
|
58
|
+
# The cassette contains a fixed public_id, so we just check it exists
|
|
59
|
+
assert result.key?('public_id')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_post_response_contains_expected_fields
|
|
64
|
+
VCR.use_cassette('client/post', record: :none) do
|
|
65
|
+
result = @client.post(nil)
|
|
66
|
+
|
|
67
|
+
# Verify response structure
|
|
68
|
+
assert result['id'].is_a?(String)
|
|
69
|
+
assert result['public_id'].is_a?(String)
|
|
70
|
+
assert result['latest_version_id'].is_a?(String)
|
|
71
|
+
assert result['latest_etag'].is_a?(String)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class ResizingModuleTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
# Reset configure before each test to ensure clean state
|
|
8
|
+
if Resizing.instance_variable_defined?(:@configure)
|
|
9
|
+
Resizing.remove_instance_variable(:@configure)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
# Reset configure after each test
|
|
15
|
+
if Resizing.instance_variable_defined?(:@configure)
|
|
16
|
+
Resizing.remove_instance_variable(:@configure)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_configure_raises_error_when_not_initialized
|
|
21
|
+
assert_raises Resizing::ConfigurationError do
|
|
22
|
+
Resizing.configure
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_configure_returns_duplicate_of_configuration
|
|
27
|
+
config = Resizing::Configuration.new(
|
|
28
|
+
image_host: 'https://test.example.com',
|
|
29
|
+
project_id: 'test_id',
|
|
30
|
+
secret_token: 'test_token'
|
|
31
|
+
)
|
|
32
|
+
Resizing.configure = config
|
|
33
|
+
|
|
34
|
+
result = Resizing.configure
|
|
35
|
+
|
|
36
|
+
assert_instance_of Resizing::Configuration, result
|
|
37
|
+
assert_equal config.image_host, result.image_host
|
|
38
|
+
assert_equal config.project_id, result.project_id
|
|
39
|
+
refute_equal config.object_id, result.object_id # Should be a duplicate
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_configure_setter_accepts_configuration_object
|
|
43
|
+
config = Resizing::Configuration.new(
|
|
44
|
+
image_host: 'https://test.example.com',
|
|
45
|
+
project_id: 'test_id',
|
|
46
|
+
secret_token: 'test_token'
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
Resizing.configure = config
|
|
50
|
+
|
|
51
|
+
assert_equal config, Resizing.instance_variable_get(:@configure)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_configure_setter_converts_hash_to_configuration
|
|
55
|
+
config_hash = {
|
|
56
|
+
image_host: 'https://hash.example.com',
|
|
57
|
+
project_id: 'hash_id',
|
|
58
|
+
secret_token: 'hash_token'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Resizing.configure = config_hash
|
|
62
|
+
|
|
63
|
+
result = Resizing.instance_variable_get(:@configure)
|
|
64
|
+
assert_instance_of Resizing::Configuration, result
|
|
65
|
+
assert_equal 'https://hash.example.com', result.image_host
|
|
66
|
+
assert_equal 'hash_id', result.project_id
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_get_raises_not_implemented_error
|
|
70
|
+
assert_raises NotImplementedError do
|
|
71
|
+
Resizing.get('test')
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_url_from_image_id_returns_url_without_version_and_transforms
|
|
76
|
+
Resizing.configure = {
|
|
77
|
+
image_host: 'https://img.example.com',
|
|
78
|
+
project_id: 'project123',
|
|
79
|
+
secret_token: 'token123'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
url = Resizing.url_from_image_id('image456')
|
|
83
|
+
|
|
84
|
+
assert_equal 'https://img.example.com/projects/project123/upload/images/image456', url
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_url_from_image_id_returns_url_with_version
|
|
88
|
+
Resizing.configure = {
|
|
89
|
+
image_host: 'https://img.example.com',
|
|
90
|
+
project_id: 'project123',
|
|
91
|
+
secret_token: 'token123'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
url = Resizing.url_from_image_id('image456', '789')
|
|
95
|
+
|
|
96
|
+
assert_equal 'https://img.example.com/projects/project123/upload/images/image456/v789', url
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_url_from_image_id_returns_url_with_transformations
|
|
100
|
+
Resizing.configure = {
|
|
101
|
+
image_host: 'https://img.example.com',
|
|
102
|
+
project_id: 'project123',
|
|
103
|
+
secret_token: 'token123'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
url = Resizing.url_from_image_id('image456', nil, [{ w: 100, h: 200 }])
|
|
107
|
+
|
|
108
|
+
assert_includes url, 'https://img.example.com/projects/project123/upload/images/image456/'
|
|
109
|
+
assert_includes url, 'w_100,h_200'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_url_from_image_id_returns_url_with_version_and_transformations
|
|
113
|
+
Resizing.configure = {
|
|
114
|
+
image_host: 'https://img.example.com',
|
|
115
|
+
project_id: 'project123',
|
|
116
|
+
secret_token: 'token123'
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
url = Resizing.url_from_image_id('image456', '789', [{ w: 100 }])
|
|
120
|
+
|
|
121
|
+
assert_includes url, 'image456/v789/'
|
|
122
|
+
assert_includes url, 'w_100'
|
|
123
|
+
end
|
|
124
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
require 'simplecov-cobertura'
|
|
4
|
+
|
|
5
|
+
SimpleCov.start do
|
|
6
|
+
add_filter "/test/"
|
|
7
|
+
|
|
8
|
+
if ENV['CI']
|
|
9
|
+
formatter SimpleCov::Formatter::CoberturaFormatter
|
|
10
|
+
else
|
|
11
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
12
|
+
SimpleCov::Formatter::SimpleFormatter,
|
|
13
|
+
SimpleCov::Formatter::HTMLFormatter
|
|
14
|
+
])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
enable_coverage :branch
|
|
18
|
+
primary_coverage :branch
|
|
19
|
+
end
|
|
2
20
|
|
|
3
21
|
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
4
22
|
require 'time'
|
|
5
23
|
require 'timecop'
|
|
6
24
|
require 'vcr'
|
|
25
|
+
require 'logger'
|
|
7
26
|
|
|
8
27
|
require 'rails'
|
|
9
28
|
require 'active_record'
|
|
@@ -13,6 +32,7 @@ require 'resizing'
|
|
|
13
32
|
require 'pry-byebug'
|
|
14
33
|
|
|
15
34
|
require 'minitest/autorun'
|
|
35
|
+
require 'minitest/mock'
|
|
16
36
|
|
|
17
37
|
VCR.configure do |c|
|
|
18
38
|
c.cassette_library_dir = 'test/vcr'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resizing
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Junichiro Kasuya
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -28,16 +28,22 @@ dependencies:
|
|
|
28
28
|
name: rails
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '6.0'
|
|
34
|
+
- - "<"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '7.1'
|
|
34
37
|
type: :development
|
|
35
38
|
prerelease: false
|
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
40
|
requirements:
|
|
38
|
-
- - "
|
|
41
|
+
- - ">="
|
|
39
42
|
- !ruby/object:Gem::Version
|
|
40
43
|
version: '6.0'
|
|
44
|
+
- - "<"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '7.1'
|
|
41
47
|
- !ruby/object:Gem::Dependency
|
|
42
48
|
name: carrierwave
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -70,16 +76,16 @@ dependencies:
|
|
|
70
76
|
name: minitest
|
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
|
72
78
|
requirements:
|
|
73
|
-
- - "
|
|
79
|
+
- - "~>"
|
|
74
80
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
81
|
+
version: '5.16'
|
|
76
82
|
type: :development
|
|
77
83
|
prerelease: false
|
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
85
|
requirements:
|
|
80
|
-
- - "
|
|
86
|
+
- - "~>"
|
|
81
87
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '
|
|
88
|
+
version: '5.16'
|
|
83
89
|
- !ruby/object:Gem::Dependency
|
|
84
90
|
name: minitest-ci
|
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,6 +142,48 @@ dependencies:
|
|
|
136
142
|
- - ">="
|
|
137
143
|
- !ruby/object:Gem::Version
|
|
138
144
|
version: '0'
|
|
145
|
+
- !ruby/object:Gem::Dependency
|
|
146
|
+
name: mysql2
|
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - ">="
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '0'
|
|
152
|
+
type: :development
|
|
153
|
+
prerelease: false
|
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0'
|
|
159
|
+
- !ruby/object:Gem::Dependency
|
|
160
|
+
name: simplecov
|
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
type: :development
|
|
167
|
+
prerelease: false
|
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0'
|
|
173
|
+
- !ruby/object:Gem::Dependency
|
|
174
|
+
name: simplecov-cobertura
|
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
|
176
|
+
requirements:
|
|
177
|
+
- - ">="
|
|
178
|
+
- !ruby/object:Gem::Version
|
|
179
|
+
version: '0'
|
|
180
|
+
type: :development
|
|
181
|
+
prerelease: false
|
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
183
|
+
requirements:
|
|
184
|
+
- - ">="
|
|
185
|
+
- !ruby/object:Gem::Version
|
|
186
|
+
version: '0'
|
|
139
187
|
description: 'Client and utilities for Resizing '
|
|
140
188
|
email:
|
|
141
189
|
- junichiro.kasuya@gmail.com
|
|
@@ -146,7 +194,7 @@ executables:
|
|
|
146
194
|
extensions: []
|
|
147
195
|
extra_rdoc_files: []
|
|
148
196
|
files:
|
|
149
|
-
- ".
|
|
197
|
+
- ".github/workflows/test.yml"
|
|
150
198
|
- ".gitignore"
|
|
151
199
|
- ".rubocop.yml"
|
|
152
200
|
- CHANGELOG.md
|
|
@@ -159,6 +207,8 @@ files:
|
|
|
159
207
|
- exe/generate-changelog
|
|
160
208
|
- exe/setup
|
|
161
209
|
- lib/resizing.rb
|
|
210
|
+
- lib/resizing/active_storage.rb
|
|
211
|
+
- lib/resizing/active_storage/service.rb
|
|
162
212
|
- lib/resizing/active_storage/service/resizing_service.rb
|
|
163
213
|
- lib/resizing/carrier_wave.rb
|
|
164
214
|
- lib/resizing/carrier_wave/storage/file.rb
|
|
@@ -171,18 +221,22 @@ files:
|
|
|
171
221
|
- lib/resizing/mock_client.rb
|
|
172
222
|
- lib/resizing/public_id.rb
|
|
173
223
|
- lib/resizing/version.rb
|
|
174
|
-
- lib/resizing/video.rb
|
|
175
|
-
- lib/resizing/video/client.rb
|
|
176
224
|
- resizing.gemspec
|
|
177
225
|
- test/data/images/empty_file.jpg
|
|
178
226
|
- test/data/images/sample1.jpg
|
|
227
|
+
- test/resizing/active_storage_service_test.rb
|
|
179
228
|
- test/resizing/carrier_wave/storage/file_test.rb
|
|
180
229
|
- test/resizing/carrier_wave/storage/remote_test.rb
|
|
181
230
|
- test/resizing/carrier_wave_test.rb
|
|
182
231
|
- test/resizing/client_test.rb
|
|
232
|
+
- test/resizing/configurable_test.rb
|
|
183
233
|
- test/resizing/configuration_test.rb
|
|
234
|
+
- test/resizing/constants_test.rb
|
|
235
|
+
- test/resizing/error_test.rb
|
|
236
|
+
- test/resizing/http_clientable_test.rb
|
|
237
|
+
- test/resizing/mock_client_test.rb
|
|
184
238
|
- test/resizing/public_id_test.rb
|
|
185
|
-
- test/
|
|
239
|
+
- test/resizing_module_test.rb
|
|
186
240
|
- test/resizing_test.rb
|
|
187
241
|
- test/test_helper.rb
|
|
188
242
|
- test/vcr/carrier_wave_test/remove_resizing_picture.yml
|
|
@@ -192,9 +246,6 @@ files:
|
|
|
192
246
|
- test/vcr/client/metadata.yml
|
|
193
247
|
- test/vcr/client/post.yml
|
|
194
248
|
- test/vcr/client/put.yml
|
|
195
|
-
- test/vcr/video/metadata/success.yml
|
|
196
|
-
- test/vcr/video/prepare/success.yml
|
|
197
|
-
- test/vcr/video/upload_completed/success.yml
|
|
198
249
|
homepage: https://github.com/jksy/resizing-gem
|
|
199
250
|
licenses:
|
|
200
251
|
- MIT
|
|
@@ -202,7 +253,7 @@ metadata:
|
|
|
202
253
|
allowed_push_host: https://rubygems.org
|
|
203
254
|
homepage_uri: https://github.com/jksy/resizing-gem
|
|
204
255
|
source_code_uri: https://github.com/jksy/resizing-gem.
|
|
205
|
-
post_install_message:
|
|
256
|
+
post_install_message:
|
|
206
257
|
rdoc_options: []
|
|
207
258
|
require_paths:
|
|
208
259
|
- lib
|
|
@@ -210,15 +261,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
210
261
|
requirements:
|
|
211
262
|
- - ">="
|
|
212
263
|
- !ruby/object:Gem::Version
|
|
213
|
-
version:
|
|
264
|
+
version: 3.0.0
|
|
214
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
266
|
requirements:
|
|
216
|
-
- - "
|
|
267
|
+
- - ">="
|
|
217
268
|
- !ruby/object:Gem::Version
|
|
218
|
-
version:
|
|
269
|
+
version: '0'
|
|
219
270
|
requirements: []
|
|
220
|
-
rubygems_version: 3.
|
|
221
|
-
signing_key:
|
|
271
|
+
rubygems_version: 3.4.19
|
|
272
|
+
signing_key:
|
|
222
273
|
specification_version: 4
|
|
223
274
|
summary: Client and utilities for Resizing
|
|
224
275
|
test_files: []
|
data/.circleci/config.yml
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
version: 2
|
|
2
|
-
|
|
3
|
-
jobs:
|
|
4
|
-
build:
|
|
5
|
-
docker:
|
|
6
|
-
- image: circleci/ruby:2.6.2-node
|
|
7
|
-
environment:
|
|
8
|
-
BUNDLE_JOBS: 4
|
|
9
|
-
BUNDLE_RETRY: 3
|
|
10
|
-
BUNDLE_PATH: vendor/bundle
|
|
11
|
-
BUNDLE_APP_CONFIG: "./.bundle"
|
|
12
|
-
TZ: /usr/share/zoneinfo/Asia/Tokyo
|
|
13
|
-
LANG: ja_JP.UTF8
|
|
14
|
-
- image: circleci/mysql:5.7
|
|
15
|
-
environment:
|
|
16
|
-
MYSQL_ROOT_PASSWORD: secret
|
|
17
|
-
MYSQL_DATABASE: resizing_gem_test
|
|
18
|
-
MYSQL_USER: resizing_gem
|
|
19
|
-
MYSQL_PASSWORD: secret
|
|
20
|
-
TZ: /usr/share/zoneinfo/Asia/Tokyo
|
|
21
|
-
LANG: ja_JP.UTF8
|
|
22
|
-
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
|
|
23
|
-
|
|
24
|
-
steps:
|
|
25
|
-
- checkout
|
|
26
|
-
- run:
|
|
27
|
-
name: Which bundler?
|
|
28
|
-
command: |
|
|
29
|
-
bundle -v
|
|
30
|
-
bundle config
|
|
31
|
-
|
|
32
|
-
- restore_cache:
|
|
33
|
-
keys:
|
|
34
|
-
- v2-{{ .Environment.CACHE_KEY }}-gem-cache-{{ arch }}-{{ .Branch }}
|
|
35
|
-
- v2-{{ .Environment.CACHE_KEY }}-gem-cache
|
|
36
|
-
|
|
37
|
-
- run:
|
|
38
|
-
name: reinstall rake && bundle install
|
|
39
|
-
command: |
|
|
40
|
-
sudo gem install bundler
|
|
41
|
-
sudo gem uninstall -x rake
|
|
42
|
-
echo "install: --no-document" >> ~/.gemrc
|
|
43
|
-
bundle config set --local path vendor/bundle
|
|
44
|
-
bundle config set --local clean true
|
|
45
|
-
bundle check || bundle install
|
|
46
|
-
|
|
47
|
-
- save_cache:
|
|
48
|
-
key: v2-{{ .Environment.CACHE_KEY }}-gem-cache-{{ arch }}-{{ .Branch }}
|
|
49
|
-
paths:
|
|
50
|
-
- vendor/bundle
|
|
51
|
-
|
|
52
|
-
- run:
|
|
53
|
-
name: connectable MySQL?
|
|
54
|
-
command: |
|
|
55
|
-
dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
|
|
56
|
-
|
|
57
|
-
# - run:
|
|
58
|
-
# name: rubocop
|
|
59
|
-
# command: bundle exec rubocop --parallel
|
|
60
|
-
# - run:
|
|
61
|
-
# name: brakeman
|
|
62
|
-
# command: bundle exec brakeman --no-exit-on-error -w 1 -z
|
|
63
|
-
- run:
|
|
64
|
-
command: bundle exec rake test
|
|
65
|
-
when: always
|
|
66
|
-
- store_test_results:
|
|
67
|
-
path: test/reports
|
|
68
|
-
|
|
69
|
-
workflows:
|
|
70
|
-
version: 2
|
|
71
|
-
build-deploy:
|
|
72
|
-
jobs:
|
|
73
|
-
- build
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Resizing
|
|
4
|
-
module Video
|
|
5
|
-
class Client
|
|
6
|
-
include Resizing::Constants
|
|
7
|
-
include Resizing::Configurable
|
|
8
|
-
include Resizing::HttpClientable
|
|
9
|
-
|
|
10
|
-
def initialize(*attrs)
|
|
11
|
-
initialize_config(*attrs)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def prepare
|
|
15
|
-
url = build_prepare_url
|
|
16
|
-
|
|
17
|
-
response = handle_faraday_error do
|
|
18
|
-
http_client.post(url) do |request|
|
|
19
|
-
request.headers['X-ResizingToken'] = config.generate_auth_header
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
handle_prepare_response response
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def upload_completed response_or_url
|
|
26
|
-
url = url_from response_or_url, 'upload_completed_url'
|
|
27
|
-
|
|
28
|
-
response = handle_faraday_error do
|
|
29
|
-
http_client.put(url) do |request|
|
|
30
|
-
request.headers['X-ResizingToken'] = config.generate_auth_header
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
handle_upload_completed_response response
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def delete response_or_url
|
|
37
|
-
url = url_from response_or_url, 'destroy_url'
|
|
38
|
-
|
|
39
|
-
response = handle_faraday_error do
|
|
40
|
-
http_client.put(url) do |request|
|
|
41
|
-
request.headers['X-ResizingToken'] = config.generate_auth_header
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
handle_upload_completed_response response
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def metadata response_or_url
|
|
48
|
-
url = url_from response_or_url, 'self_url'
|
|
49
|
-
|
|
50
|
-
response = handle_faraday_error do
|
|
51
|
-
http_client.get(url) do |request|
|
|
52
|
-
request.headers['X-ResizingToken'] = config.generate_auth_header
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
handle_metadata_response response
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def build_prepare_url
|
|
59
|
-
"#{config.video_host}/projects/#{config.project_id}/upload/videos/prepare"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
def url_from response_or_url, name
|
|
65
|
-
if response_or_url.kind_of? String
|
|
66
|
-
response_or_url
|
|
67
|
-
elsif response_or_url.kind_of? Hash
|
|
68
|
-
response_or_url[name.to_s] || response_or_url[name.intern]
|
|
69
|
-
else
|
|
70
|
-
raise ArgumentError, "upload_completed is require Hash or String"
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def handle_prepare_response response
|
|
76
|
-
raise APIError, "no response is returned" if response.nil?
|
|
77
|
-
|
|
78
|
-
case response.status
|
|
79
|
-
when HTTP_STATUS_OK, HTTP_STATUS_CREATED
|
|
80
|
-
JSON.parse(response.body)
|
|
81
|
-
else
|
|
82
|
-
handle_error_response response
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def handle_upload_completed_response response
|
|
87
|
-
raise APIError, "no response is returned" if response.nil?
|
|
88
|
-
|
|
89
|
-
case response.status
|
|
90
|
-
when HTTP_STATUS_OK
|
|
91
|
-
JSON.parse(response.body)
|
|
92
|
-
else
|
|
93
|
-
handle_error_response response
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def handle_metadata_response response
|
|
98
|
-
raise APIError, "no response is returned" if response.nil?
|
|
99
|
-
|
|
100
|
-
case response.status
|
|
101
|
-
when HTTP_STATUS_OK
|
|
102
|
-
JSON.parse(response.body)
|
|
103
|
-
else
|
|
104
|
-
handle_error_response response
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def handle_error_response response
|
|
109
|
-
result = JSON.parse(response.body) rescue {}
|
|
110
|
-
err = APIError.new("invalid http status code #{response.status}")
|
|
111
|
-
err.decoded_body = result
|
|
112
|
-
raise err
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|