tusc 0.6.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7813e93df83778b66645bbe46850bca1037d9e655d2569ec1fd704de5969dc2
4
+ data.tar.gz: f2ff22d2ddd57c4a146c1d6059c7c59ede62201d96e4c5d8af67c99487d318df
5
+ SHA512:
6
+ metadata.gz: 0a7165397f3cc3be3d77e177f312284c3b9852994d4f068c3b622eb489b34e81d437eecc5491e7165b16287f241232a3dee758774f79133adb959020e3e09d1b
7
+ data.tar.gz: d36729b3d3bb537edc066700fae5c19f4663966ba7a48cc836e4bee7b353d595a72a596b1de5848d807c90225a874265eb9060425ca987f84646701fbb64573f
@@ -0,0 +1,26 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+ # tldr: A single point of truth for code editor configuration
3
+
4
+ # conventions
5
+ # - sort each section by alpha
6
+ # - assign global defaults, then indicate exceptions to those rules
7
+
8
+ # top-most EditorConfig file
9
+ root = true
10
+
11
+ # Default settings
12
+ [*]
13
+ charset = utf-8
14
+ end_of_line = lf
15
+ indent_size = 2
16
+ insert_final_newline = true
17
+ trim_trailing_whitespace = true
18
+
19
+ # Batch files
20
+ [**.bat]
21
+ end_of_line = crlf
22
+
23
+ # Python
24
+ [**.py]
25
+ indent_size = 4
26
+ indent_style = space
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
@@ -0,0 +1,2 @@
1
+ nodejs 14.5.0
2
+ ruby 2.7.1
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,83 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a CHANGELOG](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ 2020-08-12 v0.6.1: Prepare for deploy to RubyGems
8
+ - Updated docs, using yard.
9
+
10
+ 2020-08-12 v0.6.0: Revert to basic ruby Logger, level=INFO
11
+ - switch from Ougai::Logger to Ruby Logger.
12
+ - Now, ruby/rails app can assign, e.g. `TusClient.logger = Rails.logger`
13
+ - Still logs :source
14
+ - Logger.level = Logger::INFO (was ERROR)
15
+ - Add binstub `bin/rackup` (for testing)
16
+
17
+ 2020-08-06 v0.5.0: Logged 'source' is tus code. Namespace support classes.
18
+ - Move Responsorial to TusClient namespace
19
+ - Move HttpService to TusClient namespace
20
+ - Move HttpService to lib/. lib/tusc/ is reserved for tus code.
21
+ - Logged 'source' is code from tusc dir, not support libraries
22
+ - Tests use std log (log/tusc.log) vs. log/tusc_test.log
23
+
24
+ 2020-08-05 v0.4.6: FIX CreationResponse#body, HttpService, tweak logs
25
+ - FIX CreationResponse#body (for blank body)
26
+ - Extract HttpService (head, patch, post)
27
+ - CreationRequest logs body (used by some tus servers; e.g. Vimeo)
28
+ - Log request/response vs. sending/receiving
29
+ - #truncate uses ellipse (vs. 3 periods)
30
+
31
+ 2020-07-28 v0.4.5: FIX: Upload 413 code. Extract UploadRequest (used by Uploader)
32
+ - FIX: Upload 413 code ("resource's size exceeded"), by adding ContentType to UploadRequest
33
+ - Extract UploadRequest from Uploader.push_chunk.
34
+
35
+ 2020-07-27 v0.4.4: FIX: some tus servers return 200 (vs. 204) for upload request
36
+ - added specs to split file into multiple chunks
37
+
38
+ 2020-07-24 v0.4.3: FIX: Can upload video files. Testing via tus-server.
39
+ - Added tests against local tus-server
40
+ - FIX: Uploader now supports uploading video files (using octet-stream vs. detected content type)
41
+ - removes dependency on MimeMagic
42
+ - All *Response objects have basic interface: raw, status_code, success?
43
+
44
+ 2020-07-23 v0.4.2: FIX: Uploader#push_chunk had error logging (truncated) body
45
+
46
+ 2020-07-23 v0.4.1: FIX: Upload#perform seeks correct offset.
47
+
48
+ 2020-07-23 v0.4.0: FIX: OffsetResponse default offset, Uploader#content_type
49
+ - FIX: OffsetResponse#offset is 0, if Upload-Offset header is not present
50
+ - Uploader#content_type detects or uses default
51
+
52
+ 2020-07-23 v0.3.0: FIX: content_type. Allow setting TusClient.log_level
53
+ - debug by setting `TusClient.log_level = Logger::DEBUG`
54
+ - reduce log rollover sizes to 1MB (200kB for testing)
55
+ - FIX: Get appropriate field from MimeMagic or return default type
56
+
57
+ 2020-07-22 v0.2.0: Uploader & OffsetRequest accept extra_headers
58
+ - Uploader passes extra_headers to OffsetRequest
59
+
60
+ 2020-07-22 v0.1.6: FIX Requesting offset
61
+ - FIX: Uploader#offset_request(er)
62
+ - OffsetRequest: accepts URL or URI
63
+
64
+ 2020-07-22 v0.1.5: FIX Requires, FIX #blank CONST conflicts
65
+ - FIX: Uploader requires OffsetRequest
66
+ - FIX: #blank no longer creates BLANK_RE const if rails already has (via client)
67
+
68
+ 2020-07-22 v0.1.4: CreationResponse#success?, #blank?
69
+ - CreationResponse: body is parsed from JSON
70
+ - Copy/paste #blank? from Rails/ActiveSupport
71
+ - FIX: Uploader.from_file_path factory method (named args)
72
+
73
+ 2020-07-22 v0.1.3: CreationRequest accepts :body, :extra_headers
74
+ - i.e. Vimeo tus server requires info to be included in the request.
75
+
76
+ 2020-07-22 v0.1.2 CreationResponse provides #status_code, #body, #raw
77
+
78
+ 2020-07-22 v0.1.0: Removed ActiveSupport dependency
79
+
80
+ 2020-07-21 v0.1.0: Support basic requests:
81
+ - Creation Request (POST): requests URL we can upload to
82
+ - Current Offset Request (HEAD): requests current offset fo specified file upload url
83
+ - Upload Request (PATCH): uploads a chunk of the file
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matt@scilipoti.name. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ ruby '2.7.1'
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in tusc_rb.gemspec
8
+ gemspec
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tusc (0.6.1)
5
+ ougai (~> 1.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ amazing_print (1.2.1)
13
+ byebug (11.1.3)
14
+ coderay (1.1.3)
15
+ content_disposition (1.0.0)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.4.4)
19
+ hashdiff (1.0.1)
20
+ method_source (1.0.0)
21
+ oj (3.10.8)
22
+ ougai (1.8.5)
23
+ oj (~> 3.10)
24
+ pry (0.13.1)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ pry-byebug (3.9.0)
28
+ byebug (~> 11.0)
29
+ pry (~> 0.13.0)
30
+ public_suffix (4.0.5)
31
+ rack (2.2.3)
32
+ rake (13.0.1)
33
+ roda (3.34.0)
34
+ rack
35
+ rspec (3.9.0)
36
+ rspec-core (~> 3.9.0)
37
+ rspec-expectations (~> 3.9.0)
38
+ rspec-mocks (~> 3.9.0)
39
+ rspec-core (3.9.2)
40
+ rspec-support (~> 3.9.3)
41
+ rspec-expectations (3.9.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-mocks (3.9.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-support (3.9.3)
48
+ safe_yaml (1.0.5)
49
+ tus-server (2.3.0)
50
+ content_disposition (~> 1.0)
51
+ roda (>= 2.27, < 4)
52
+ webmock (3.8.3)
53
+ addressable (>= 2.3.6)
54
+ crack (>= 0.3.2)
55
+ hashdiff (>= 0.4.0, < 2.0.0)
56
+ yard (0.9.25)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ amazing_print (~> 1.2)
63
+ bundler (~> 1.17)
64
+ pry-byebug (~> 3.9)
65
+ rake (~> 13.0)
66
+ rspec (~> 3.0)
67
+ tus-server (~> 2.3)
68
+ tusc!
69
+ webmock (~> 3.8)
70
+ yard (~> 0.9)
71
+
72
+ RUBY VERSION
73
+ ruby 2.7.1p83
74
+
75
+ BUNDLED WITH
76
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Matt Scilipoti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ # tusc.rb: Tus Client for Ruby
2
+
3
+ tusc.rb is a Ruby client for the [tus resumable upload protocol](http://tus.io), version 1.0.0.
4
+
5
+ > **tus** is a protocol based on HTTP for *resumable file uploads*. Resumable
6
+ > means that an upload can be interrupted at any moment and can be resumed without
7
+ > re-uploading the previous data again. An interruption may happen willingly, if
8
+ > the user wants to pause, or by accident in case of an network issue or server
9
+ > outage.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'tusc'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install tusc
26
+
27
+ ## Usage
28
+
29
+ - Perform a CreationRequest
30
+ - Create an Uploader, passing the:
31
+ - IO object (file)
32
+ - Upload URL (provided by the Creation Request)
33
+ - Start the upload
34
+
35
+ > We recommend reviewing the specs in `spec/against_tus_server_spec.rb`. There are examples of uploading files (e.g. text, video).
36
+
37
+ ### Example
38
+
39
+ ```
40
+ File.open('path/to/file') do |file|
41
+ creation_request = TusClient::CreationRequest.new(
42
+ tus_creation_url: 'https://example.com',
43
+ file_size: file.size
44
+ )
45
+ creation_response = creation_request.perform
46
+ uploader = TusClient::Uploader.new(
47
+ io: file,
48
+ upload_url: creation_response.upload_url.to_s
49
+ )
50
+ uploader.perform
51
+ end
52
+ ```
53
+
54
+ ## Logging
55
+
56
+ We log to `log/tusc.log`.
57
+
58
+ - You can adjust verbosity by setting `TusClient.log_level`
59
+ - It defaults to `Logger::INFO`
60
+
61
+ > Tip: Can combine with Rails logs using `TusClient.logger = Rails.logger`
62
+
63
+ > Tip: "bunyan" is good tool for viewing "pretty" formatted logs. Note: we're recommend [the CLI](https://github.com/trentm/node-bunyan#installation), not the nodejs library.
64
+
65
+ ## tus overview
66
+
67
+ > from https://tus.io/faq.html#how-does-tus-work
68
+
69
+ A tus upload is broken down into different HTTP requests, where each one has a different purpose:
70
+
71
+ At first, the client sends a POST request to the server to initiate the upload. This upload creation request tells the server basic information about the upload, such as its size or additional metadata. If the server accepts this upload creation request, it will return a successfully response with the Location header set to the upload URL. The upload URL is used to unique identify and reference the newly created upload resource.
72
+
73
+ Once the upload has been create, the client can start to transmit the actual upload content by sending a PATCH request to the upload URL, as returned in the previous POST request. Idealy, this PATCH request should contain as much upload content as possible to minimize the upload duration. The PATCH request must also contain the Upload-Offset header which tells the server at which byte-offset the server should write the uploaded data. If the PATCH request successfully transfers the entire upload content, then your upload is done!
74
+
75
+ If the PATCH request got interrupted or failed for another reason, the client can attempt to resume the upload. In order to resume, the client must know how much data the server has received. This information is obtained by sending a HEAD request to the upload URL and inspecting the returned Upload-Offset header. Once the client knows the upload offset, it can send another PATCH request until the upload is completely down.
76
+
77
+ 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.
78
+
79
+ ## TODO:
80
+ - [X] Basic upload (via creation request and upload)
81
+ - [X] Can pass tus_server specific/extra headers (like Vimeo requires)
82
+ - [ ] Can resume failed upload
83
+ - [ ] Supports Upload-Metadata
84
+ - [ ] Supports Upload-Defer-Length
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+
90
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
+
92
+ ## Testing
93
+
94
+ - We use rspec, so everything is under `spec/` directory.
95
+ - Run via `bin/rspec` or `rake` (the default rake task is :spec)
96
+ - Fixture files used for testing are in `spec/fixtures`.
97
+ - To test against an actual tus server, run one via `bin/rackup`
98
+
99
+ ## Contributing
100
+
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mattscilipoti/tusc.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
102
+
103
+ ## License
104
+
105
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
106
+
107
+ ## Code of Conduct
108
+
109
+ Everyone interacting in the TusClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mattscilipoti/tusc.rb/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec