resizing 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 447b0dda55d606eec4ec8133edd826cd206719ebe44c839c6a2628092ff8eaca
4
- data.tar.gz: 8bb995ba29217cd573fc1eeaec86aad1a0f999513aa89cb598eec8ea168a5ef0
3
+ metadata.gz: 961f81c9e1882479073ee48e278c966ef695a81ea550bcf9d44d1c47b3e85f70
4
+ data.tar.gz: a1d9a4227b6bbd1b014d250bb85f7ab8d40a32ae2fdd55ff6df79a0ba75f7e7b
5
5
  SHA512:
6
- metadata.gz: 9d899143122b31fc588b6c721f1fd889edf203a43de5b09a2e0164dd3a075d92b3fb3936f7d0e0c154b6c994dddc748e190c2e7ab8327690aed1b31a96bc886c
7
- data.tar.gz: a621e2b3c388c3d9b6cea438589f2fe4474465ca6fe78aa4e97977c10857da4ef48c89883690c3db4b782b8b58871fa1fa37e8ff69bc8ce67f05b84cb95d80ec
6
+ metadata.gz: b3425a65764ce43cccf114f34344789f2690c308f8853ae5497d9cd5466da08fdc10aa96d57dec3edb86f777166c0f7eda6aedf12ebd0b400d6a07ed150121fa
7
+ data.tar.gz: d788fa2b2ce69001db90edcca01cc817e06f9bc3674b57e9ce066b7d9e67933c831f8df61aa95a0b31370db8ab0e80ae0ccac53400a573411277cc301656aa1a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased](https://github.com/jksy/resizing-gem/tree/v0.8.0)
4
+
5
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.7.0...v0.8.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add supporting API of videos [\#47](https://github.com/jksy/resizing-gem/pull/47) ([jksy](https://github.com/jksy))
10
+ - update changelog and add rake task [\#44](https://github.com/jksy/resizing-gem/pull/44) ([jksy](https://github.com/jksy))
11
+
12
+ ## [v0.7.0](https://github.com/jksy/resizing-gem/tree/v0.7.0) (2020-12-11)
13
+
14
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.6.0...v0.7.0)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - v0.7.0 [\#43](https://github.com/jksy/resizing-gem/pull/43) ([jksy](https://github.com/jksy))
19
+ - APIError\#decoded\_body return hash always [\#42](https://github.com/jksy/resizing-gem/pull/42) ([jksy](https://github.com/jksy))
20
+
21
+ ## [v0.6.0](https://github.com/jksy/resizing-gem/tree/v0.6.0) (2020-12-08)
22
+
23
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.5.3...v0.6.0)
24
+
25
+ **Merged pull requests:**
26
+
27
+ - return error message [\#41](https://github.com/jksy/resizing-gem/pull/41) ([jksy](https://github.com/jksy))
28
+
3
29
  ## [v0.5.3](https://github.com/jksy/resizing-gem/tree/v0.5.3) (2020-10-15)
4
30
 
5
31
  [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.5.2...v0.5.3)
@@ -7,6 +33,7 @@
7
33
  **Merged pull requests:**
8
34
 
9
35
  - Feature/fix raise error [\#40](https://github.com/jksy/resizing-gem/pull/40) ([jksy](https://github.com/jksy))
36
+ - save original filename [\#37](https://github.com/jksy/resizing-gem/pull/37) ([jksy](https://github.com/jksy))
10
37
 
11
38
  ## [v0.5.2](https://github.com/jksy/resizing-gem/tree/v0.5.2) (2020-10-11)
12
39
 
@@ -39,7 +66,6 @@
39
66
 
40
67
  **Merged pull requests:**
41
68
 
42
- - save original filename [\#37](https://github.com/jksy/resizing-gem/pull/37) ([jksy](https://github.com/jksy))
43
69
  - columnがnilの時はdefault\_urlを返す \#33 [\#34](https://github.com/jksy/resizing-gem/pull/34) ([jksy](https://github.com/jksy))
44
70
 
45
71
  ## [v0.2.1](https://github.com/jksy/resizing-gem/tree/v0.2.1) (2020-09-29)
@@ -90,6 +116,7 @@
90
116
 
91
117
  - version 0.2.0 [\#21](https://github.com/jksy/resizing-gem/pull/21) ([jksy](https://github.com/jksy))
92
118
  - support f\_auto, q\_auto parameter [\#20](https://github.com/jksy/resizing-gem/pull/20) ([jksy](https://github.com/jksy))
119
+ - add mock client for test environments [\#14](https://github.com/jksy/resizing-gem/pull/14) ([jksy](https://github.com/jksy))
93
120
 
94
121
  ## [v0.1.4](https://github.com/jksy/resizing-gem/tree/v0.1.4) (2020-08-08)
95
122
 
@@ -111,10 +138,6 @@
111
138
 
112
139
  [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.1...v0.1.2)
113
140
 
114
- **Merged pull requests:**
115
-
116
- - ignore response if delete method is received 404 status code [\#17](https://github.com/jksy/resizing-gem/pull/17) ([jksy](https://github.com/jksy))
117
-
118
141
  ## [v0.1.1](https://github.com/jksy/resizing-gem/tree/v0.1.1) (2020-06-12)
119
142
 
120
143
  [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.0...v0.1.1)
@@ -122,7 +145,6 @@
122
145
  **Merged pull requests:**
123
146
 
124
147
  - Feature/fix raise error [\#16](https://github.com/jksy/resizing-gem/pull/16) ([jksy](https://github.com/jksy))
125
- - change mysql port on docker-compose [\#9](https://github.com/jksy/resizing-gem/pull/9) ([jksy](https://github.com/jksy))
126
148
 
127
149
  ## [v0.1.0](https://github.com/jksy/resizing-gem/tree/v0.1.0) (2020-06-07)
128
150
 
@@ -130,11 +152,12 @@
130
152
 
131
153
  **Merged pull requests:**
132
154
 
133
- - add mock client for test environments [\#14](https://github.com/jksy/resizing-gem/pull/14) ([jksy](https://github.com/jksy))
155
+ - ignore response if delete method is received 404 status code [\#17](https://github.com/jksy/resizing-gem/pull/17) ([jksy](https://github.com/jksy))
134
156
  - Feature/add test test for remove xxx [\#13](https://github.com/jksy/resizing-gem/pull/13) ([jksy](https://github.com/jksy))
135
157
  - add rubocop & fix some tests [\#12](https://github.com/jksy/resizing-gem/pull/12) ([jksy](https://github.com/jksy))
136
158
  - fix the column cant be update by null value [\#11](https://github.com/jksy/resizing-gem/pull/11) ([jksy](https://github.com/jksy))
137
159
  - fix empty url when model is reload [\#10](https://github.com/jksy/resizing-gem/pull/10) ([jksy](https://github.com/jksy))
160
+ - change mysql port on docker-compose [\#9](https://github.com/jksy/resizing-gem/pull/9) ([jksy](https://github.com/jksy))
138
161
  - fix return invalid url when model is reloaded [\#8](https://github.com/jksy/resizing-gem/pull/8) ([jksy](https://github.com/jksy))
139
162
  - add circleci [\#7](https://github.com/jksy/resizing-gem/pull/7) ([jksy](https://github.com/jksy))
140
163
  - divide some classes and add tests [\#6](https://github.com/jksy/resizing-gem/pull/6) ([jksy](https://github.com/jksy))
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'minitest', '~> 5.0'
9
- gem 'rake', '~> 12.0'
9
+ gem 'rake', '~> 13.0'
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
+ require 'github_changelog_generator/task'
5
6
 
6
7
  Rake::TestTask.new(:test) do |t|
7
8
  t.libs << 'test'
@@ -9,4 +10,11 @@ Rake::TestTask.new(:test) do |t|
9
10
  t.test_files = FileList['test/**/*_test.rb']
10
11
  end
11
12
 
13
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
14
+ config.user = 'jksy'
15
+ config.project = 'resizing-gem'
16
+ config.since_tag = 'v0.1.0'
17
+ config.future_release = Resizing::VERSION
18
+ end
19
+
12
20
  task default: :test
data/lib/resizing.rb CHANGED
@@ -5,11 +5,15 @@ require 'faraday'
5
5
  require 'json'
6
6
 
7
7
  module Resizing
8
+ autoload :Constants, 'resizing/constants'
9
+ autoload :Configurable, 'resizing/configurable'
10
+ autoload :HttpClientable, 'resizing/http_clientable'
8
11
  autoload :Client, 'resizing/client'
9
12
  autoload :MockClient, 'resizing/mock_client'
10
13
  autoload :Configuration, 'resizing/configuration'
11
14
  autoload :CarrierWave, 'resizing/carrier_wave'
12
15
  autoload :PublicId, 'resizing/public_id'
16
+ autoload :Video, 'resizing/video'
13
17
 
14
18
  class Error < StandardError; end
15
19
  class ConfigurationError < Error; end
@@ -24,21 +24,12 @@ module Resizing
24
24
  #
25
25
  #++
26
26
  class Client
27
- # TODO
28
- # to use standard constants
29
- HTTP_STATUS_OK = 200
30
- HTTP_STATUS_CREATED = 201
31
- HTTP_STATUS_NOT_FOUND = 404
27
+ include Resizing::Constants
28
+ include Resizing::Configurable
29
+ include Resizing::HttpClientable
32
30
 
33
- attr_reader :config
34
31
  def initialize(*attrs)
35
- @config = if attrs.first.is_a? Configuration
36
- attrs.first
37
- elsif attrs.first.nil?
38
- Resizing.configure
39
- else
40
- Configuration.new(*attrs)
41
- end
32
+ initialize_config(*attrs)
42
33
  end
43
34
 
44
35
  def get(image_id)
@@ -57,14 +48,14 @@ module Resizing
57
48
  image: Faraday::UploadIO.new(body, options[:content_type], filename)
58
49
  }
59
50
 
60
- response = http_client.post(url, params) do |request|
61
- request.headers['X-ResizingToken'] = config.generate_auth_header
51
+ response = handle_faraday_error do
52
+ http_client.post(url, params) do |request|
53
+ request.headers['X-ResizingToken'] = config.generate_auth_header
54
+ end
62
55
  end
63
56
 
64
57
  result = handle_create_response(response)
65
58
  result
66
- rescue Faraday::TimeoutError => e
67
- handle_timeout_error e
68
59
  end
69
60
 
70
61
  def put(image_id, file_or_binary, options)
@@ -79,40 +70,40 @@ module Resizing
79
70
  image: Faraday::UploadIO.new(body, options[:content_type], filename)
80
71
  }
81
72
 
82
- response = http_client.put(url, params) do |request|
83
- request.headers['X-ResizingToken'] = config.generate_auth_header
73
+ response = handle_faraday_error do
74
+ http_client.put(url, params) do |request|
75
+ request.headers['X-ResizingToken'] = config.generate_auth_header
76
+ end
84
77
  end
85
78
 
86
79
  result = handle_create_response(response)
87
80
  result
88
- rescue Faraday::TimeoutError => e
89
- handle_timeout_error e
90
81
  end
91
82
 
92
83
  def delete(image_id)
93
84
  url = build_delete_url(image_id)
94
85
 
95
- response = http_client.delete(url) do |request|
96
- request.headers['X-ResizingToken'] = config.generate_auth_header
86
+ response = handle_faraday_error do
87
+ http_client.delete(url) do |request|
88
+ request.headers['X-ResizingToken'] = config.generate_auth_header
89
+ end
97
90
  end
98
91
 
99
92
  result = handle_delete_response(response)
100
93
  result
101
- rescue Faraday::TimeoutError => e
102
- handle_timeout_error e
103
94
  end
104
95
 
105
96
  def metadata(image_id, options = {})
106
97
  url = build_metadata_url(image_id)
107
98
 
108
- response = http_client.get(url) do |request|
109
- request.headers['X-ResizingToken'] = config.generate_auth_header
99
+ response = handle_faraday_error do
100
+ http_client.get(url) do |request|
101
+ request.headers['X-ResizingToken'] = config.generate_auth_header
102
+ end
110
103
  end
111
104
 
112
105
  result = handle_metadata_response(response)
113
106
  result
114
- rescue Faraday::TimeoutError => e
115
- handle_timeout_error e
116
107
  end
117
108
 
118
109
  private
@@ -142,15 +133,6 @@ module Resizing
142
133
  "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}/metadata"
143
134
  end
144
135
 
145
- def http_client
146
- @http_client ||= Faraday.new(url: config.host) do |builder|
147
- builder.options[:open_timeout] = config.open_timeout
148
- builder.options[:timeout] = config.response_timeout
149
- builder.request :multipart
150
- builder.request :url_encoded
151
- builder.adapter Faraday.default_adapter
152
- end
153
- end
154
136
 
155
137
  def to_io(data)
156
138
  return data.to_io if data.respond_to? :to_io
@@ -208,10 +190,5 @@ module Resizing
208
190
  raise err
209
191
  end
210
192
  end
211
-
212
- def handle_timeout_error error
213
- # error: Faraday::TimeoutError
214
- raise APIError.new("TimeoutError: #{error.inspect}")
215
- end
216
193
  end
217
194
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resizing
4
+ module Configurable
5
+ def self.included mod
6
+ mod.send(:attr_reader, :config)
7
+ end
8
+
9
+ def initialize_config *attrs
10
+ config = if attrs.first.is_a? Configuration
11
+ attrs.first
12
+ elsif attrs.first.nil?
13
+ Resizing.configure
14
+ else
15
+ Configuration.new(*attrs)
16
+ end
17
+
18
+ instance_variable_set :@config, config
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resizing
4
+ module Constants
5
+ HTTP_STATUS_OK = 200
6
+ HTTP_STATUS_CREATED = 201
7
+ HTTP_STATUS_NOT_FOUND = 404
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resizing
4
+ module HttpClientable
5
+ def http_client
6
+ @http_client ||= Faraday.new(url: config.host) do |builder|
7
+ builder.options[:open_timeout] = config.open_timeout
8
+ builder.options[:timeout] = config.response_timeout
9
+ builder.request :multipart
10
+ builder.request :url_encoded
11
+ builder.adapter Faraday.default_adapter
12
+ end
13
+ end
14
+
15
+ def handle_faraday_error &block
16
+ yield
17
+ rescue Faraday::TimeoutError => e
18
+ handle_timeout_error e
19
+ end
20
+
21
+ def handle_timeout_error error
22
+ raise APIError.new("TimeoutError: #{error.inspect}")
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resizing
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resizing
4
+ module Video
5
+ autoload :Client, 'resizing/video/client'
6
+ end
7
+ end
8
+
@@ -0,0 +1,105 @@
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 metadata response_or_url
37
+ url = url_from response_or_url, 'self_url'
38
+
39
+ response = handle_faraday_error do
40
+ http_client.get(url) do |request|
41
+ request.headers['X-ResizingToken'] = config.generate_auth_header
42
+ end
43
+ end
44
+ handle_metadata_response response
45
+ end
46
+
47
+ private
48
+
49
+ def build_prepare_url
50
+ "#{config.host}/projects/#{config.project_id}/upload/videos/prepare"
51
+ end
52
+
53
+ def url_from response_or_url, name
54
+ if response_or_url.kind_of? String
55
+ response_or_url
56
+ elsif response_or_url.kind_of? Hash
57
+ response_or_url[name.to_s] || response_or_url[name.intern]
58
+ else
59
+ raise ArgumentError, "upload_completed is require Hash or String"
60
+ end
61
+ end
62
+
63
+
64
+ def handle_prepare_response response
65
+ raise APIError, "no response is returned" if response.nil?
66
+
67
+ case response.status
68
+ when HTTP_STATUS_OK, HTTP_STATUS_CREATED
69
+ JSON.parse(response.body)
70
+ else
71
+ handle_error_response response
72
+ end
73
+ end
74
+
75
+ def handle_upload_completed_response response
76
+ raise APIError, "no response is returned" if response.nil?
77
+
78
+ case response.status
79
+ when HTTP_STATUS_OK
80
+ JSON.parse(response.body)
81
+ else
82
+ handle_error_response response
83
+ end
84
+ end
85
+
86
+ def handle_metadata_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_error_response response
98
+ result = JSON.parse(response.body) rescue {}
99
+ err = APIError.new("invalid http status code #{response.status}")
100
+ err.decoded_body = result
101
+ raise err
102
+ end
103
+ end
104
+ end
105
+ end
data/resizing.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
- spec.add_runtime_dependency 'faraday', '~> 1.0.1'
31
+ spec.add_runtime_dependency 'faraday', '>= 1.0.1', '< 1.4.0'
32
32
  spec.add_development_dependency 'byebug'
33
33
  spec.add_development_dependency 'carrierwave'
34
34
  spec.add_development_dependency 'fog-aws'
@@ -40,4 +40,5 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'rubocop'
41
41
  spec.add_development_dependency 'timecop'
42
42
  spec.add_development_dependency 'vcr'
43
+ spec.add_development_dependency 'github_changelog_generator'
43
44
  end
@@ -5,7 +5,6 @@ require 'test_helper'
5
5
  module Resizing
6
6
  class ClientTest < Minitest::Test
7
7
  def setup
8
- # NOP
9
8
  @configuration_template = {
10
9
  host: 'http://192.168.56.101:5000',
11
10
  project_id: 'e06e710d-f026-4dcf-b2c0-eab0de8bb83f',
@@ -53,6 +52,16 @@ module Resizing
53
52
  end
54
53
  end
55
54
 
55
+ def test_is_timeout_with_post_method
56
+ Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
57
+
58
+ client = Resizing::Client.new
59
+ f = File.open('test/data/images/sample1.jpg', 'r')
60
+ assert_raises Resizing::APIError do
61
+ client.post(f, content_type: 'image/jpeg')
62
+ end
63
+ end
64
+
56
65
  def test_is_putable_file
57
66
  Resizing.configure = @configuration_template
58
67
 
@@ -75,6 +84,18 @@ module Resizing
75
84
  end
76
85
  end
77
86
 
87
+ def test_is_timeout_with_put_method
88
+ Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
89
+
90
+ client = Resizing::Client.new
91
+ name = 'AWEaewfAreaweFAFASfwe'
92
+ f = File.open('test/data/images/sample1.jpg', 'r')
93
+
94
+ assert_raises Resizing::APIError do
95
+ r = client.put(name, f, content_type: 'image/jpeg')
96
+ end
97
+ end
98
+
78
99
  def test_raise_error
79
100
  Resizing.configure = @configuration_template
80
101
 
@@ -117,12 +138,12 @@ module Resizing
117
138
  assert_equal(r['id'], name)
118
139
  assert_equal(r['project_id'], Resizing.configure.project_id)
119
140
  assert_equal(r['content_type'], 'image/jpeg')
120
- assert(!r['latest_version_id'].nil?)
121
- assert(!r['latest_etag'].nil?)
122
- assert(!r['created_at'].nil?)
123
- assert(!r['updated_at'].nil?)
124
- assert(!r['height'].nil?)
125
- assert(!r['width'].nil?)
141
+ assert(r['latest_version_id'] != nil)
142
+ assert(r['latest_etag'] != nil)
143
+ assert(r['created_at'] != nil)
144
+ assert(r['updated_at'] != nil)
145
+ assert(r['height'] != nil)
146
+ assert(r['width'] != nil)
126
147
  assert_equal(
127
148
  r['public_id'],
128
149
  "/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo"
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Resizing
6
+ module Video
7
+ class ClientTest < Minitest::Test
8
+ def setup
9
+ # TODO
10
+ # refactoring
11
+ @configuration_template = {
12
+ host: 'http://192.168.56.101:5000',
13
+ project_id: 'f11dfad4-2247-4220-b3b2-efeb82864a97',
14
+ secret_token: 'xn2fkkrrp2uiragliaigkx3mwnmjis6dg35sa3kya12sq133t3xjp36s7iwamp64',
15
+ open_timeout: 10,
16
+ response_timeout: 20
17
+ }
18
+ end
19
+
20
+ def teardown
21
+ # NOP
22
+ end
23
+
24
+ def test_is_initialized
25
+ Resizing.configure = @configuration_template
26
+
27
+ client = Resizing::Video::Client.new
28
+ assert(!client.config.nil?)
29
+ assert_equal(client.config, Resizing.configure)
30
+ end
31
+
32
+ def test_is_initialized_with_configuration
33
+ config = Resizing::Configuration.new(@configuration_template)
34
+ client = Resizing::Video::Client.new(config)
35
+ assert(!client.config.nil?)
36
+ assert_equal(client.config, config)
37
+ end
38
+
39
+ def test_is_callable_prepare
40
+ Resizing.configure = @configuration_template
41
+
42
+ client = Resizing::Video::Client.new
43
+ VCR.use_cassette 'video/prepare/success', record: :once do
44
+ base_url = 'http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d'
45
+ r = client.prepare
46
+ assert_equal(r['id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
47
+ assert_equal(r['project_id'], Resizing.configure.project_id)
48
+ assert_equal(r['state'], 'initialized')
49
+ assert_nil(r['deleted_at'])
50
+ # assert_nil(r['source_uri']) # TODO: remove
51
+ assert(r['s3_presigned_url'] != nil)
52
+ assert_nil(r['converted_uri']) # TODO:remove
53
+ assert(r['created_at'] != nil)
54
+ assert(r['updated_at'] != nil)
55
+ assert(r['upload_completed_url'], "#{base_url}/upload_completed")
56
+ assert(r['self_url'], "#{base_url}.json")
57
+ assert_nil(r['m3u8_url'])
58
+ assert_nil(r['avc_url'])
59
+ assert_nil(r['hevc_url'])
60
+ assert_includes(r['thumbnail_url'], 'now-converting')
61
+ end
62
+ end
63
+
64
+ def test_is_timeout_with_prepare_method
65
+ Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
66
+
67
+ client = Resizing::Video::Client.new
68
+ assert_raises Resizing::APIError do
69
+ client.prepare
70
+ end
71
+ end
72
+
73
+ def test_is_callable_upload_complete_with_response
74
+ Resizing.configure = @configuration_template
75
+
76
+ client = Resizing::Video::Client.new
77
+ r = nil
78
+ VCR.use_cassette 'video/prepare/success', record: :once do
79
+ r = client.prepare
80
+ end
81
+
82
+ VCR.use_cassette 'video/upload_completed/success', record: :once do
83
+ r = client.upload_completed r
84
+ assert_upload_completed_response r
85
+ end
86
+ end
87
+
88
+ def test_is_callable_upload_complete_with_string
89
+ Resizing.configure = @configuration_template
90
+
91
+ client = Resizing::Video::Client.new
92
+ r = nil
93
+ VCR.use_cassette 'video/prepare/success', record: :once do
94
+ r = client.prepare
95
+ end
96
+
97
+ VCR.use_cassette 'video/upload_completed/success', record: :once do
98
+ r = client.upload_completed r['upload_completed_url']
99
+ assert_upload_completed_response r
100
+ end
101
+ end
102
+
103
+ def test_is_callable_metadata_with_response
104
+ Resizing.configure = @configuration_template
105
+
106
+ client = Resizing::Video::Client.new
107
+ r = nil
108
+ VCR.use_cassette 'video/prepare/success', record: :once do
109
+ r = client.prepare
110
+ end
111
+
112
+ completed_response = nil
113
+ VCR.use_cassette 'video/upload_completed/success', record: :once do
114
+ completed_response = client.upload_completed r['upload_completed_url']
115
+ end
116
+
117
+ VCR.use_cassette 'video/metadata/success', record: :once do
118
+ r = client.metadata r
119
+ assert_equal(completed_response, r)
120
+ end
121
+ end
122
+
123
+ def assert_upload_completed_response r
124
+ base_url = 'http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d'
125
+ assert_equal(r['id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
126
+ assert_equal(r['project_id'], Resizing.configure.project_id)
127
+ assert_equal(r['state'], 'uploaded')
128
+ assert_nil(r['deleted_at'])
129
+ # assert(r['source_uri'] != nil) # TODO: remove
130
+ assert(r['s3_presigned_url'] != nil)
131
+ # assert_equal(r['converted_uri'], "#{base_url}/") # TODO:remove
132
+ assert(r['created_at'] != nil)
133
+ assert(r['updated_at'] != nil)
134
+ assert(r['upload_completed_url'], "#{base_url}/upload_completed")
135
+ assert(r['self_url'], "#{base_url}.json")
136
+ assert_nil(r['m3u8_url'])
137
+ assert_nil(r['avc_url'])
138
+ assert_nil(r['hevc_url'])
139
+ assert_includes(r['thumbnail_url'], 'now-converting')
140
+ assert_equal(r['job_state']['id'], 'a586d38f-bdc3-4af2-9dbc-e0c18d2d54c5')
141
+ assert_equal(r['job_state']['upload_video_id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
142
+ assert_equal(r['job_state']['state'], 'initialized')
143
+ assert_equal(r['job_state']['job_percent_complete'], 0)
144
+ assert(r['job_state']['created_at'] != nil)
145
+ assert(r['job_state']['updated_at'] != nil)
146
+ end
147
+ end
148
+ end
149
+ end
data/test/test_helper.rb CHANGED
@@ -18,6 +18,11 @@ VCR.configure do |c|
18
18
  c.cassette_library_dir = 'test/vcr'
19
19
  c.hook_into :faraday
20
20
  c.allow_http_connections_when_no_cassette = false
21
+
22
+ # raise Faraday::TimeoutError, when project_id is timeout_project_id
23
+ c.before_http_request(lambda {|r| URI(r.uri).path.match? %r(/projects/timeout_project_id) } ) do
24
+ raise Faraday::TimeoutError
25
+ end
21
26
  end
22
27
 
23
28
  ActiveRecord::Base.establish_connection(
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ X-ResizingToken:
13
+ - v1,1611308558,a02cf32edef894208f6d1bc17cc6182783728e2b2edfdca1bf6b3109fe37a58d
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ x-frame-options:
20
+ - SAMEORIGIN
21
+ x-xss-protection:
22
+ - 1; mode=block
23
+ x-content-type-options:
24
+ - nosniff
25
+ x-download-options:
26
+ - noopen
27
+ x-permitted-cross-domain-policies:
28
+ - none
29
+ referrer-policy:
30
+ - strict-origin-when-cross-origin
31
+ content-type:
32
+ - application/json; charset=utf-8
33
+ etag:
34
+ - W/"f2386fd24b9a80cecab7721608aa8902"
35
+ cache-control:
36
+ - max-age=0, private, must-revalidate
37
+ x-request-id:
38
+ - 84895278-9508-45c0-a7dc-d1087dc68813
39
+ x-runtime:
40
+ - '0.023674'
41
+ transfer-encoding:
42
+ - chunked
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","project_id":"f11dfad4-2247-4220-b3b2-efeb82864a97","state":"uploaded","source_uri":"s3://resizing-bucket-development-video/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","deleted_at":null,"s3_presigned_url":"https://resizing-bucket-development-video.s3.ap-northeast-1.amazonaws.com/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIXXXXXXXXXX%2F20210122%2Fap-northeast-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210122T094237Z\u0026X-Amz-Expires=900\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=c847ca1bfc20b7caeefcb999697df3cfd531aa2b7f0aa13f9066f289f693c22d","converted_uri":"s3://resizing-bucket-development-video/videos/converted/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","created_at":"2021-01-22T09:42:37.670Z","updated_at":"2021-01-22T09:42:37.878Z","upload_completed_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d/upload_completed","self_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json","m3u8_url":null,"hevc_url":null,"avc_url":null,"thumbnail_url":"/assets/videos/now-converting-8a05d294385c14270a3662e01df5e50578cabcd2787123c18057ac06b101344c.png","job_state":{"id":"a586d38f-bdc3-4af2-9dbc-e0c18d2d54c5","upload_video_id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","state":"initialized","job_percent_complete":0,"created_at":"2021-01-22T09:42:38.501Z","updated_at":"2021-01-22T09:42:38.501Z"}}'
46
+ recorded_at: Fri, 22 Jan 2021 09:42:38 GMT
47
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/prepare
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ X-ResizingToken:
13
+ - v1,1611308557,6628235db472f228a7c3c6b309e081b6c32aac01890abbfd2f38230ff4105c1c
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ x-frame-options:
20
+ - SAMEORIGIN
21
+ x-xss-protection:
22
+ - 1; mode=block
23
+ x-content-type-options:
24
+ - nosniff
25
+ x-download-options:
26
+ - noopen
27
+ x-permitted-cross-domain-policies:
28
+ - none
29
+ referrer-policy:
30
+ - strict-origin-when-cross-origin
31
+ content-type:
32
+ - application/json; charset=utf-8
33
+ etag:
34
+ - W/"273d4e663c17e06deb0c69cc90bb79b6"
35
+ cache-control:
36
+ - max-age=0, private, must-revalidate
37
+ x-request-id:
38
+ - e586873a-9cc9-45a0-a216-5e62165cb9f1
39
+ x-runtime:
40
+ - '0.046932'
41
+ transfer-encoding:
42
+ - chunked
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","project_id":"f11dfad4-2247-4220-b3b2-efeb82864a97","state":"initialized","source_uri":"s3://resizing-bucket-development-video/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","deleted_at":null,"s3_presigned_url":"https://resizing-bucket-development-video.s3.ap-northeast-1.amazonaws.com/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIXXXXXXXXXXXXXX%2F20210122%2Fap-northeast-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210122T094237Z\u0026X-Amz-Expires=900\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=c847ca1bfc20b7caeefcb999697df3cfd531aa2b7f0aa13f9066f289f693c22d","converted_uri":null,"created_at":"2021-01-22T09:42:37.670Z","updated_at":"2021-01-22T09:42:37.670Z","upload_completed_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d/upload_completed","self_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json","m3u8_url":null,"hevc_url":null,"avc_url":null,"thumbnail_url":"/assets/videos/now-converting-8a05d294385c14270a3662e01df5e50578cabcd2787123c18057ac06b101344c.png","job_state":null}'
46
+ recorded_at: Fri, 22 Jan 2021 09:42:37 GMT
47
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d/upload_completed
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ X-ResizingToken:
13
+ - v1,1611308557,6628235db472f228a7c3c6b309e081b6c32aac01890abbfd2f38230ff4105c1c
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ x-frame-options:
20
+ - SAMEORIGIN
21
+ x-xss-protection:
22
+ - 1; mode=block
23
+ x-content-type-options:
24
+ - nosniff
25
+ x-download-options:
26
+ - noopen
27
+ x-permitted-cross-domain-policies:
28
+ - none
29
+ referrer-policy:
30
+ - strict-origin-when-cross-origin
31
+ content-type:
32
+ - application/json; charset=utf-8
33
+ etag:
34
+ - W/"f7ce780fcb3afdb5077ccfee0564b182"
35
+ cache-control:
36
+ - max-age=0, private, must-revalidate
37
+ x-request-id:
38
+ - 8a79b573-8db2-474c-a994-9e1ff59bc6c1
39
+ x-runtime:
40
+ - '0.830313'
41
+ transfer-encoding:
42
+ - chunked
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"project_id":"f11dfad4-2247-4220-b3b2-efeb82864a97","id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","state":"uploaded","source_uri":"s3://resizing-bucket-development-video/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","deleted_at":null,"s3_presigned_url":"https://resizing-bucket-development-video.s3.ap-northeast-1.amazonaws.com/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIXXXXXXXXXX%2F20210122%2Fap-northeast-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210122T094237Z\u0026X-Amz-Expires=900\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=c847ca1bfc20b7caeefcb999697df3cfd531aa2b7f0aa13f9066f289f693c22d","converted_uri":"s3://resizing-bucket-development-video/videos/converted/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","created_at":"2021-01-22T09:42:37.670Z","updated_at":"2021-01-22T09:42:37.878Z","upload_completed_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d/upload_completed","self_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json","m3u8_url":null,"hevc_url":null,"avc_url":null,"thumbnail_url":"/assets/videos/now-converting-8a05d294385c14270a3662e01df5e50578cabcd2787123c18057ac06b101344c.png","job_state":{"id":"a586d38f-bdc3-4af2-9dbc-e0c18d2d54c5","upload_video_id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","state":"initialized","job_percent_complete":0,"created_at":"2021-01-22T09:42:38.501Z","updated_at":"2021-01-22T09:42:38.501Z"}}'
46
+ recorded_at: Fri, 22 Jan 2021 09:42:38 GMT
47
+ recorded_with: VCR 6.0.0
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resizing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichiro Kasuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.0.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.4.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: byebug
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +184,20 @@ dependencies:
178
184
  - - ">="
179
185
  - !ruby/object:Gem::Version
180
186
  version: '0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: github_changelog_generator
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
181
201
  description: 'Client and utilities for Resizing '
182
202
  email:
183
203
  - junichiro.kasuya@gmail.com
@@ -203,10 +223,15 @@ files:
203
223
  - lib/resizing/carrier_wave/storage/file.rb
204
224
  - lib/resizing/carrier_wave/storage/remote.rb
205
225
  - lib/resizing/client.rb
226
+ - lib/resizing/configurable.rb
206
227
  - lib/resizing/configuration.rb
228
+ - lib/resizing/constants.rb
229
+ - lib/resizing/http_clientable.rb
207
230
  - lib/resizing/mock_client.rb
208
231
  - lib/resizing/public_id.rb
209
232
  - lib/resizing/version.rb
233
+ - lib/resizing/video.rb
234
+ - lib/resizing/video/client.rb
210
235
  - resizing.gemspec
211
236
  - test/data/images/empty_file.jpg
212
237
  - test/data/images/sample1.jpg
@@ -216,6 +241,7 @@ files:
216
241
  - test/resizing/client_test.rb
217
242
  - test/resizing/configuration_test.rb
218
243
  - test/resizing/public_id_test.rb
244
+ - test/resizing/video/client_test.rb
219
245
  - test/resizing_test.rb
220
246
  - test/test_helper.rb
221
247
  - test/vcr/carrier_wave_test/remove_resizing_picture.yml
@@ -225,6 +251,9 @@ files:
225
251
  - test/vcr/client/metadata.yml
226
252
  - test/vcr/client/post.yml
227
253
  - test/vcr/client/put.yml
254
+ - test/vcr/video/metadata/success.yml
255
+ - test/vcr/video/prepare/success.yml
256
+ - test/vcr/video/upload_completed/success.yml
228
257
  homepage: https://github.com/jksy/resizing-gem
229
258
  licenses:
230
259
  - MIT