Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize gem. #85

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkg
*~
*.swo
*.swp
/Gemfile.lock
/gems.locked
/.rspec_status
6 changes: 0 additions & 6 deletions .yardopts

This file was deleted.

8 changes: 0 additions & 8 deletions Gemfile

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

9 changes: 0 additions & 9 deletions Manifest.txt

This file was deleted.

69 changes: 31 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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 = {
Expand All @@ -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': {
Expand All @@ -144,45 +142,40 @@ 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
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
Expand Down
8 changes: 0 additions & 8 deletions Rakefile

This file was deleted.

8 changes: 8 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

gemspec

group :maintenance, optional: true do
gem "bake-gem"
gem "bake-modernize"
end
31 changes: 14 additions & 17 deletions multipart-post.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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