-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from trainline-eu/add-part-params-class-to-a…
…llow-multipart-posts-with-json-content-and-file-upload Create PartParams class to allow multipart posts with JSON content and file upload at the same time
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faraday | ||
# Allows multipart posts while specifying headers of a part | ||
class ParamPart | ||
def initialize(value, content_type, content_id = nil) | ||
@value = value | ||
@content_type = content_type | ||
@content_id = content_id | ||
end | ||
|
||
def to_part(boundary, key) | ||
Faraday::Parts::Part.new(boundary, key, value, headers) | ||
end | ||
|
||
def headers | ||
{ | ||
'Content-Type' => content_type, | ||
'Content-ID' => content_id | ||
} | ||
end | ||
|
||
attr_reader :value, :content_type, :content_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters