From e89db8aa879845ed2cc434467c99d59f5e89bfd7 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 2 Jun 2022 23:55:56 +1200 Subject: [PATCH] Modernize gem. --- .../workflows/{ruby.yml => development.yml} | 0 .gitignore | 2 +- .yardopts | 6 -- Gemfile | 8 --- LICENSE | 21 ------ Manifest.txt | 9 --- README.md | 69 +++++++++---------- Rakefile | 8 --- gems.rb | 8 +++ multipart-post.gemspec | 31 ++++----- 10 files changed, 54 insertions(+), 108 deletions(-) rename .github/workflows/{ruby.yml => development.yml} (100%) delete mode 100644 .yardopts delete mode 100644 Gemfile delete mode 100644 LICENSE delete mode 100644 Manifest.txt delete mode 100644 Rakefile create mode 100644 gems.rb diff --git a/.github/workflows/ruby.yml b/.github/workflows/development.yml similarity index 100% rename from .github/workflows/ruby.yml rename to .github/workflows/development.yml diff --git a/.gitignore b/.gitignore index 3290571..fe5340a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ pkg *~ *.swo *.swp -/Gemfile.lock +/gems.locked /.rspec_status diff --git a/.yardopts b/.yardopts deleted file mode 100644 index 12595ba..0000000 --- a/.yardopts +++ /dev/null @@ -1,6 +0,0 @@ ---no-private -lib/**/*.rb -- -History.txt -LICENSE -README.md diff --git a/Gemfile b/Gemfile deleted file mode 100644 index aef3a75..0000000 --- a/Gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -source 'https://rubygems.org' -gemspec - -group :development, :test do - gem 'rake' -end diff --git a/LICENSE b/LICENSE deleted file mode 100644 index ce550a3..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright (c) 2007-2013 Nick Sieger nick@nicksieger.com -Copyright, 2017, by Samuel G. D. Williams. - -MIT license. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Manifest.txt b/Manifest.txt deleted file mode 100644 index 109d8f0..0000000 --- a/Manifest.txt +++ /dev/null @@ -1,9 +0,0 @@ -lib/composite_io.rb -lib/multipartable.rb -lib/parts.rb -lib/net/http/post/multipart.rb -Manifest.txt -Rakefile -README.txt -test/test_composite_io.rb -test/net/http/post/test_multipart.rb diff --git a/README.md b/README.md index d5e6368..0a9fb37 100644 --- a/README.md +++ b/README.md @@ -3,27 +3,25 @@ Adds a streamy multipart form post capability to `Net::HTTP`. Also supports other methods besides `POST`. -[![Ruby CI](https://github.com/socketry/multipart-post/actions/workflows/ruby.yml/badge.svg)](https://github.com/socketry/multipart-post/actions/workflows/ruby.yml) +[![Development Status](https://github.com/socketry/multipart-post/workflows/Development/badge.svg)](https://github.com/socketry/multipart-post/actions?workflow=Development) ## Features/Problems -* Appears to actually work. A good feature to have. -* Encapsulates posting of file/binary parts and name/value parameter parts, similar to - most browsers' file upload forms. -* Provides an `UploadIO` helper class to prepare IO objects for inclusion in the params - hash of the multipart post object. + - Appears to actually work. A good feature to have. + - Encapsulates posting of file/binary parts and name/value parameter parts, similar to + most browsers' file upload forms. + - Provides an `UploadIO` helper class to prepare IO objects for inclusion in the params + hash of the multipart post object. ## Installation - gem install multipart-post - -or in your Gemfile - - gem 'multipart-post' +``` shell +bundle add multipart-post +``` ## Usage -```ruby +``` ruby require 'net/http/post/multipart' url = URI.parse('http://www.example.com/upload') @@ -39,7 +37,7 @@ end To post multiple files or attachments, simply include multiple parameters with `UploadIO` values: -```ruby +``` ruby require 'net/http/post/multipart' url = URI.parse('http://www.example.com/upload') @@ -55,7 +53,7 @@ To post files with other normal, non-file params such as input values, you need In Rails 4 for example: -```ruby +``` ruby def model_params require_params = params.require(:model).permit(:param_one, :param_two, :param_three, :avatar) require_params[:avatar] = model_params[:avatar].present? ? UploadIO.new(model_params[:avatar].tempfile, model_params[:avatar].content_type, model_params[:avatar].original_filename) : nil @@ -76,7 +74,7 @@ end Or in plain ruby: -```ruby +``` ruby def params(file) params = { "description" => "A nice picture!" } params[:datei] = UploadIO.new(file, "image/jpeg", "image.jpg") @@ -93,13 +91,14 @@ end ``` ### Parts Headers -By default, all individual parts will include the header `Content-Disposition` as well as `Content-Length`, `Content-Transfer-Encoding` and `Content-Type` for the File Parts. + +By default, all individual parts will include the header `Content-Disposition` as well as `Content-Length`, `Content-Transfer-Encoding` and `Content-Type` for the File Parts. You may optionally configure the headers `Content-Type` and `Content-ID` for both ParamPart and FilePart by passing in a `parts` header. -For example: +For example: -```ruby +``` ruby url = URI.parse('http://www.example.com/upload') params = { @@ -118,22 +117,21 @@ headers = { req = Net::HTTP::Post::Multipart.new(uri, params, headers) ``` -This would configure the `file_metadata_01` part to include `Content-Type` +This would configure the `file_metadata_01` part to include `Content-Type` -``` -Content-Disposition: form-data; name="file_metadata_01" -Content-Type: application/json - { - "description" => "A nice picture!" - } -``` + Content-Disposition: form-data; name="file_metadata_01" + Content-Type: application/json + { + "description" => "A nice picture!" + } #### Custom Parts Headers + *For FileParts only.* -You can include any number of custom parts headers in addition to `Content-Type` and `Content-ID`. +You can include any number of custom parts headers in addition to `Content-Type` and `Content-ID`. -```ruby +``` ruby headers = { 'parts': { 'file_metadata_01': { @@ -144,20 +142,18 @@ headers = { } ``` - - ### Debugging You can debug requests and responses (e.g. status codes) for all requests by adding the following code: -```ruby +``` ruby http = Net::HTTP.new(uri.host, uri.port) http.set_debug_output($stdout) ``` ## Versioning -This library aims to adhere to [Semantic Versioning 2.0.0][semver]. +This library aims to adhere to [Semantic Versioning 2.0.0](http://semver.org/). Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that @@ -165,24 +161,21 @@ restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a -dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision. +dependency on this gem using the [Pessimistic Version Constraint](http://guides.rubygems.org/patterns/#pessimistic-version-constraint) with two digits of precision. For example: -```ruby +``` ruby spec.add_dependency 'multipart-post', '~> 2.1' ``` -[semver]: http://semver.org/ -[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint - ## License Released under the MIT license. Copyright, 2007-2013, by [Nick Sieger](https://nicksieger.com). Copyright, 2017, by [Samuel G. D. Williams](https://www.codeotaku.com). -Copyright, 2019, by [Patrick Davey](https://psdavey.com). +Copyright, 2019, by [Patrick Davey](https://psdavey.com). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 366c7f8..0000000 --- a/Rakefile +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require "bundler/gem_tasks" -require "rspec/core/rake_task" - -RSpec::Core::RakeTask.new(:test) - -task :default => :test diff --git a/gems.rb b/gems.rb new file mode 100644 index 0000000..265a51e --- /dev/null +++ b/gems.rb @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gemspec + +group :maintenance, optional: true do + gem "bake-gem" + gem "bake-modernize" +end diff --git a/multipart-post.gemspec b/multipart-post.gemspec index 4bb39b3..c972708 100644 --- a/multipart-post.gemspec +++ b/multipart-post.gemspec @@ -3,21 +3,18 @@ require_relative "lib/multipart/post/version" Gem::Specification.new do |spec| - spec.name = "multipart-post" - spec.version = Multipart::Post::VERSION - spec.authors = ["Nick Sieger", "Samuel Williams"] - spec.email = ["nick@nicksieger.com", "samuel.williams@oriontransfer.co.nz"] - spec.homepage = "https://github.com/nicksieger/multipart-post" - spec.summary = %q{A multipart form post accessory for Net::HTTP.} - spec.license = "MIT" - spec.description = %q{Use with Net::HTTP to do multipart form postspec. IO values that have #content_type, #original_filename, and #local_path will be posted as a binary file.} - - spec.files = `git ls-files`.split("\n") - spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - spec.require_paths = ["lib"] - - spec.add_development_dependency 'bundler', ['>= 1.3', '< 3'] - spec.add_development_dependency 'rspec', '~> 3.4' - spec.add_development_dependency 'rake' + spec.name = "multipart-post" + spec.version = Multipart::Post::VERSION + + spec.summary = "A multipart form post accessory for Net::HTTP." + spec.authors = ["Nick Sieger", "Samuel Williams", "Olle Jonsson", "McClain Looney", "Lewis Cowles", "Gustav Ernberg", "Patrick Davey", "Steven Davidovitz", "Alex Koppel", "Ethan Turkeltaub", "Jagtesh Chadha", "Nick", "VincWebwag", "hasimo", "hexfet", "Christine Yen", "David Moles", "Eric Hutzelman", "Feuda Nan", "Gerrit Riessen", "Jan Piotrowski", "Jan-Joost Spanjers", "Jason Moore", "Jeff Hodges", "Johannes Wagener", "Jordi Massaguer Pla", "Lachlan Priest", "Leo Cassarani", "Lonre Wang", "Luke Redpath", "Matt Colyer", "Mislav Marohnić", "Socrates Vicente", "Steffen Grunwald", "Tim Barkley"] + spec.license = "MIT" + + spec.homepage = "https://github.com/socketry/multipart-post" + + spec.files = Dir.glob('{lib}/**/*', File::FNM_DOTMATCH, base: __dir__) + + spec.add_development_dependency "bundler" + spec.add_development_dependency "rake" + spec.add_development_dependency "rspec", "~> 3.4" end