tusc 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +25 -1
- data/README.md +33 -3
- data/lib/http_service.rb +5 -0
- data/lib/tusc.rb +18 -4
- data/lib/tusc/options_request.rb +35 -0
- data/lib/tusc/options_response.rb +36 -0
- data/lib/tusc/responsorial.rb +4 -1
- data/lib/tusc/uploader.rb +3 -5
- data/lib/tusc/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a71525b9433f284775aff54411ad90d5a8cfe03a69fcbc779f57c7183231215
|
4
|
+
data.tar.gz: 19fa4e6742d79887d5e94796d07ccb87fb39310f05e639aa7a293ee1f78855b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b35190435554684f5e7b923a2ff9ca06b819ffe31f3062d87129d992b901e8fbf9687b8511c24ebff106a2c34a6dac6f4a2af3e121a1332fa4df49e512ba59d
|
7
|
+
data.tar.gz: 9c18e9a86285fda886b4ef7f3838d991cb10f11d5ca145acd9c453931a9b888a392549ab7720ec7b51d7fdc53562014d08f6bd9d656e1be19231ec4ce3b23bcc
|
data/.travis.yml
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
---
|
2
|
+
# TravisCI config info: https://docs.codeclimate.com/docs/travis-ci-test-coverage
|
3
|
+
env:
|
4
|
+
global:
|
5
|
+
- CC_TEST_REPORTER_ID=304a38cb2ff3b8a793c4079709b23fd514812a8bbf694cb290a3afe31cf8f04a
|
2
6
|
language: ruby
|
3
7
|
bundler_args: --with ci
|
4
8
|
cache: bundler
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
5
13
|
script: bundle exec rake spec_ci
|
14
|
+
after_script:
|
15
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
6
16
|
rvm:
|
7
17
|
- 2.7
|
8
18
|
- 2.6
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a CHANGELOG](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
+
2020-08-20 v0.7.0: Support OPTIONS request, TusClient.chunk_size=, code coverage metric
|
8
|
+
- Support OPTIONS request via OptionsRequest/Response classes
|
9
|
+
- Increase default chunk_size to 10MB
|
10
|
+
- Can assign uploaded chunk_size via TusClient.chunk_size
|
11
|
+
- Readme lists "What is supported?"
|
12
|
+
- Add Coveralls (for [code coverage](https://coveralls.io/r/mattscilipoti/tusc.rb) in Travis CI)
|
13
|
+
- Add CodeClimate support and badge
|
14
|
+
|
7
15
|
2020-08-13 v0.6.3: Fix Travis CI error (local tus server)
|
8
16
|
- Remove unused 'ougai' gem
|
9
17
|
- Move dev/test/ci dependencies to Gemfile
|
data/Gemfile
CHANGED
@@ -8,10 +8,12 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
8
8
|
gemspec
|
9
9
|
|
10
10
|
gem 'amazing_print', '~> 1.2', :group => [:development, :test]
|
11
|
+
gem 'coveralls', '~> 0.8', require: false, :group => [:development, :test, :ci]
|
11
12
|
gem 'bundler', '~> 1.17', :group => [:development, :test, :ci]
|
12
13
|
gem 'pry-byebug', '~> 3.9', :group => [:development, :test]
|
13
14
|
gem 'rake', '~> 13.0', :group => [:development, :test, :ci]
|
14
15
|
gem 'rspec', '~> 3.0', :group => [:development, :test, :ci]
|
16
|
+
gem 'rspec-its', '~> 1.3', require: false, :group => [:development, :test, :ci]
|
15
17
|
gem 'tus-server', '~> 2.3', require: false, :group => [:development]
|
16
18
|
gem 'webmock', '~> 3.8', require: false, :group => [:development]
|
17
19
|
gem 'yard', '~> 0.9', require: false, :group => [:development]
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tusc (0.
|
4
|
+
tusc (0.7.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -12,10 +12,18 @@ GEM
|
|
12
12
|
byebug (11.1.3)
|
13
13
|
coderay (1.1.3)
|
14
14
|
content_disposition (1.0.0)
|
15
|
+
coveralls (0.8.23)
|
16
|
+
json (>= 1.8, < 3)
|
17
|
+
simplecov (~> 0.16.1)
|
18
|
+
term-ansicolor (~> 1.3)
|
19
|
+
thor (>= 0.19.4, < 2.0)
|
20
|
+
tins (~> 1.6)
|
15
21
|
crack (0.4.3)
|
16
22
|
safe_yaml (~> 1.0.0)
|
17
23
|
diff-lcs (1.4.4)
|
24
|
+
docile (1.3.2)
|
18
25
|
hashdiff (1.0.1)
|
26
|
+
json (2.3.1)
|
19
27
|
method_source (1.0.0)
|
20
28
|
pry (0.13.1)
|
21
29
|
coderay (~> 1.1)
|
@@ -37,11 +45,25 @@ GEM
|
|
37
45
|
rspec-expectations (3.9.2)
|
38
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
47
|
rspec-support (~> 3.9.0)
|
48
|
+
rspec-its (1.3.0)
|
49
|
+
rspec-core (>= 3.0.0)
|
50
|
+
rspec-expectations (>= 3.0.0)
|
40
51
|
rspec-mocks (3.9.1)
|
41
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
53
|
rspec-support (~> 3.9.0)
|
43
54
|
rspec-support (3.9.3)
|
44
55
|
safe_yaml (1.0.5)
|
56
|
+
simplecov (0.16.1)
|
57
|
+
docile (~> 1.1)
|
58
|
+
json (>= 1.8, < 3)
|
59
|
+
simplecov-html (~> 0.10.0)
|
60
|
+
simplecov-html (0.10.2)
|
61
|
+
sync (0.5.0)
|
62
|
+
term-ansicolor (1.7.1)
|
63
|
+
tins (~> 1.0)
|
64
|
+
thor (1.0.1)
|
65
|
+
tins (1.25.0)
|
66
|
+
sync
|
45
67
|
tus-server (2.3.0)
|
46
68
|
content_disposition (~> 1.0)
|
47
69
|
roda (>= 2.27, < 4)
|
@@ -57,9 +79,11 @@ PLATFORMS
|
|
57
79
|
DEPENDENCIES
|
58
80
|
amazing_print (~> 1.2)
|
59
81
|
bundler (~> 1.17)
|
82
|
+
coveralls (~> 0.8)
|
60
83
|
pry-byebug (~> 3.9)
|
61
84
|
rake (~> 13.0)
|
62
85
|
rspec (~> 3.0)
|
86
|
+
rspec-its (~> 1.3)
|
63
87
|
tus-server (~> 2.3)
|
64
88
|
tusc!
|
65
89
|
webmock (~> 3.8)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# tusc.rb: Tus Client for Ruby
|
2
2
|
|
3
|
-
tusc.rb is a Ruby client for the [tus resumable upload protocol](http://tus.io),
|
3
|
+
tusc.rb is a (tested) Ruby client for the [tus resumable upload protocol](http://tus.io), for Tus-Resumable v1.0.0. Supporting the Core Protocol and some Extentions (see [What is Supported?](#what-is-supported))
|
4
4
|
|
5
5
|
> **tus** is a protocol based on HTTP for *resumable file uploads*. Resumable
|
6
6
|
> means that an upload can be interrupted at any moment and can be resumed without
|
@@ -10,6 +10,10 @@ tusc.rb is a Ruby client for the [tus resumable upload protocol](http://tus.io),
|
|
10
10
|
|
11
11
|
[![Gem](https://img.shields.io/gem/v/tusc)](https://github.com/mattscilipoti.tusc.rb)
|
12
12
|
[![Build Status](https://travis-ci.com/mattscilipoti/tusc.rb.svg?branch=master&logo=travis)](https://travis-ci.com/mattscilipoti/tusc.rb)
|
13
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/93198b592f31d691658d/maintainability)](https://codeclimate.com/github/mattscilipoti/tusc.rb/maintainability)
|
14
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/93198b592f31d691658d/test_coverage)](https://codeclimate.com/github/mattscilipoti/tusc.rb/test_coverage)
|
15
|
+
[![Test Coverage](https://coveralls.io/repos/mattscilipoti/tusc.rb/badge.svg?branch=master)](https://coveralls.io/r/mattscilipoti/tusc.rb)
|
16
|
+
|
13
17
|
![Ruby 2.7.x](https://img.shields.io/badge/ruby-2.7-blue)
|
14
18
|
![Ruby 2.6.x](https://img.shields.io/badge/ruby-2.6-blue)
|
15
19
|
![Ruby 2.5.x](https://img.shields.io/badge/ruby-2.5-blue)
|
@@ -36,11 +40,19 @@ Or install it yourself as:
|
|
36
40
|
- Perform a CreationRequest
|
37
41
|
- Create an Uploader, passing the:
|
38
42
|
- IO object (file)
|
39
|
-
- Upload URL (provided by the
|
43
|
+
- Upload URL (provided by the CreationReponse)
|
40
44
|
- Start the upload
|
41
45
|
|
42
46
|
> We recommend reviewing the specs in `spec/against_tus_server_spec.rb`. There are examples of uploading files (e.g. text, video).
|
43
47
|
|
48
|
+
> Each request type has a corresponding response type, which surfaces important information.
|
49
|
+
|
50
|
+
> To be uploaded, files are broken into "chunks". You can assign a different chunk size, in bytes,
|
51
|
+
> via `TusClient.chunk_size=`.
|
52
|
+
> Note: chunk_size is often bigger than the file size (thus creating one chunk).
|
53
|
+
|
54
|
+
> You can pass extra information via :extra_headers and/or :body params. This is helpful for special headers (e.g. Upload-Defer-Length) and tus servers that that need extra information.
|
55
|
+
|
44
56
|
### Example
|
45
57
|
|
46
58
|
```
|
@@ -85,11 +97,29 @@ If the PATCH request got interrupted or failed for another reason, the client ca
|
|
85
97
|
|
86
98
|
Optionally, if the client wants to delete an upload because it won’t be needed anymore, a DELETE request can be sent to the upload URL. After this, the upload can be cleaned up by the server and resuming the upload is not possible anymore.
|
87
99
|
|
100
|
+
## What is supported?
|
101
|
+
|
102
|
+
Core Protocol:
|
103
|
+
|
104
|
+
- [X] [HEAD](https://tus.io/protocols/resumable-upload.html#head) (via OffsetRequest/Response)
|
105
|
+
- [X] [PATCH](https://tus.io/protocols/resumable-upload.html#patch) (via UploadRequest/Response)
|
106
|
+
- [X] [OPTIONS](https://tus.io/protocols/resumable-upload.html#options) (via OptionsRequest/Response)
|
107
|
+
|
108
|
+
Protocol Extensions:
|
109
|
+
|
110
|
+
- [X] [Creation](https://tus.io/protocols/resumable-upload.html#creation) (via CreationRequest/Response)
|
111
|
+
- [ ] [Creation With Upload](https://tus.io/protocols/resumable-upload.html#creation-with-upload)
|
112
|
+
- [ ] [Checksum](https://tus.io/protocols/resumable-upload.html#checksum)
|
113
|
+
- [ ] [Termination](https://tus.io/protocols/resumable-upload.html#termination)
|
114
|
+
- [ ] [Concatenation](https://tus.io/protocols/resumable-upload.html#concatenation)
|
115
|
+
|
116
|
+
|
88
117
|
## TODO:
|
89
118
|
- [X] Basic upload (via creation request and upload)
|
90
119
|
- [X] Can pass tus_server specific/extra headers (like Vimeo requires)
|
120
|
+
- [ ] TusMaxSize (from OptionsRequest) informs max_chunk_size of UploadRequest
|
91
121
|
- [ ] Can resume failed upload
|
92
|
-
- [
|
122
|
+
- [x] Supports "Upload-Metadata" header for POST (via extra_headers of CreationRequest)
|
93
123
|
- [ ] Supports Upload-Defer-Length
|
94
124
|
|
95
125
|
## Development
|
data/lib/http_service.rb
CHANGED
@@ -9,6 +9,11 @@ class TusClient::HttpService
|
|
9
9
|
_perform(http_request: request, logger: logger)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.options(uri:, headers:, logger:)
|
13
|
+
request = Net::HTTP::Options.new(uri, headers)
|
14
|
+
_perform(http_request: request, logger: logger)
|
15
|
+
end
|
16
|
+
|
12
17
|
def self.patch(uri:, headers:, body:, logger:)
|
13
18
|
request = Net::HTTP::Patch.new(uri, headers)
|
14
19
|
request.body = body
|
data/lib/tusc.rb
CHANGED
@@ -2,6 +2,7 @@ require 'logger'
|
|
2
2
|
require 'tusc/version'
|
3
3
|
require_relative 'core_ext/object/blank'
|
4
4
|
require_relative 'tusc/creation_request'
|
5
|
+
require_relative 'tusc/options_request'
|
5
6
|
require_relative 'tusc/uploader'
|
6
7
|
|
7
8
|
class Logger::LogDevice
|
@@ -33,19 +34,18 @@ module TusClient
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.log_level
|
36
|
-
|
37
|
+
logger.level
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.log_level=(value)
|
40
|
-
|
41
|
-
@log_level = value
|
41
|
+
logger.level = value
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.logger
|
45
45
|
@logger ||= begin
|
46
46
|
# logger = Logger.new(STDOUT)
|
47
47
|
Logger.new(log_dir.join('tusc.log'), 1, 1 * MEGABYTE).tap do |logger|
|
48
|
-
logger.level =
|
48
|
+
logger.level = Logger::INFO
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -53,4 +53,18 @@ module TusClient
|
|
53
53
|
def self.logger=(value)
|
54
54
|
@logger = value
|
55
55
|
end
|
56
|
+
|
57
|
+
# Uploaded files are split into "chunks"
|
58
|
+
# This provides the size of each chunk, in bytes
|
59
|
+
def self.chunk_size
|
60
|
+
@chunk_size ||= 10 * TusClient::MEGABYTE
|
61
|
+
end
|
62
|
+
|
63
|
+
# Uploaded files are split into "chunks"
|
64
|
+
# This allows you to assign the size of each chunk, in bytes
|
65
|
+
# chunk_size is often bigger than the size of the uploaded file (thus creating one chunk)
|
66
|
+
def self.chunk_size=(value)
|
67
|
+
raise(ArgumentError, "chunk_size must be an Integer (#{value}).") unless value.is_a?(Integer)
|
68
|
+
@chunk_size = value
|
69
|
+
end
|
56
70
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../http_service'
|
2
|
+
require_relative 'options_response'
|
3
|
+
|
4
|
+
# Asks tus server for the provided options (aka server configuration)
|
5
|
+
class TusClient::OptionsRequest
|
6
|
+
attr_reader :extra_headers, :tus_server_uri
|
7
|
+
def initialize(tus_server_url:, extra_headers: {})
|
8
|
+
tus_server_uri = tus_server_url.is_a?(URI) ? tus_server_url : URI.parse(tus_server_url)
|
9
|
+
unless tus_server_uri.is_a?(URI::HTTP) && !tus_server_uri.host.nil?
|
10
|
+
raise URI::InvalidURIError, "Could NOT parse host from #{tus_server_url.inspect}"
|
11
|
+
end
|
12
|
+
|
13
|
+
@tus_server_uri = tus_server_uri
|
14
|
+
@extra_headers = extra_headers
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers
|
18
|
+
extra_headers
|
19
|
+
end
|
20
|
+
|
21
|
+
def logger
|
22
|
+
@logger ||= TusClient.logger
|
23
|
+
end
|
24
|
+
|
25
|
+
# Retrieves server config via a OPTIONS request to the tus server
|
26
|
+
# Returns an OptionsResponse)
|
27
|
+
def perform
|
28
|
+
response = TusClient::HttpService.options(
|
29
|
+
uri: tus_server_uri,
|
30
|
+
headers: headers,
|
31
|
+
logger: logger
|
32
|
+
)
|
33
|
+
TusClient::OptionsResponse.new(response)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'responsorial'
|
2
|
+
|
3
|
+
# Parses the response from an OptionsRequest
|
4
|
+
#
|
5
|
+
# Surfacing important info:
|
6
|
+
# - max_chunk_size
|
7
|
+
# - supported_checksums
|
8
|
+
# - supported_extensions
|
9
|
+
# - supported_versions
|
10
|
+
class TusClient::OptionsResponse
|
11
|
+
include TusClient::Responsorial
|
12
|
+
def initialize(response)
|
13
|
+
@response = response
|
14
|
+
end
|
15
|
+
|
16
|
+
def max_chunk_size
|
17
|
+
raw.header['Tus-Max-Size']
|
18
|
+
end
|
19
|
+
|
20
|
+
def success?
|
21
|
+
success_codes = [200, 204]
|
22
|
+
success_codes.include?(status_code)
|
23
|
+
end
|
24
|
+
|
25
|
+
def supported_checksums
|
26
|
+
raw.header['Tus-Checksum-Algorithm']
|
27
|
+
end
|
28
|
+
|
29
|
+
def supported_extensions
|
30
|
+
raw.header['Tus-Extension']
|
31
|
+
end
|
32
|
+
|
33
|
+
def supported_versions
|
34
|
+
raw.header['Tus-Version']
|
35
|
+
end
|
36
|
+
end
|
data/lib/tusc/responsorial.rb
CHANGED
data/lib/tusc/uploader.rb
CHANGED
@@ -8,10 +8,6 @@ require_relative 'offset_request'
|
|
8
8
|
class TusClient::Uploader
|
9
9
|
attr_reader :extra_headers, :io, :upload_url
|
10
10
|
|
11
|
-
def self.chunk_size
|
12
|
-
10 * TusClient::MEGABYTE
|
13
|
-
end
|
14
|
-
|
15
11
|
def self.default_content_type
|
16
12
|
'application/offset+octet-stream'
|
17
13
|
end
|
@@ -45,8 +41,10 @@ class TusClient::Uploader
|
|
45
41
|
delete upload_url
|
46
42
|
end
|
47
43
|
|
44
|
+
# Uploaded files are split into "chunks"
|
45
|
+
# This provides the size, in bytes, of each chunk
|
48
46
|
def chunk_size
|
49
|
-
@chunk_size ||= TusClient
|
47
|
+
@chunk_size ||= TusClient.chunk_size
|
50
48
|
end
|
51
49
|
|
52
50
|
def content_type
|
data/lib/tusc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tusc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Scilipoti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- lib/tusc/creation_response.rb
|
42
42
|
- lib/tusc/offset_request.rb
|
43
43
|
- lib/tusc/offset_response.rb
|
44
|
+
- lib/tusc/options_request.rb
|
45
|
+
- lib/tusc/options_response.rb
|
44
46
|
- lib/tusc/responsorial.rb
|
45
47
|
- lib/tusc/upload_request.rb
|
46
48
|
- lib/tusc/upload_response.rb
|