-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e2e391
commit 6d5ef6c
Showing
3 changed files
with
38 additions
and
64 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,32 @@ | ||
class Restfulie::Client::Feature::SerializeBody | ||
|
||
def execute(flow, request, response, env) | ||
|
||
if should_have_payload?(request.method) | ||
|
||
payload = env[:body] | ||
if payload && !(payload.kind_of?(String) && payload.empty?) | ||
type = headers['Content-Type'] | ||
raise Restfulie::Common::Error::RestfulieError, "Missing content type related to the data to be submitted" unless type | ||
|
||
marshaller = Restfulie::Common::Converter.content_type_for(type) | ||
raise Restfulie::Common::Error::RestfulieError, "Missing content type for #{type} related to the data to be submitted" unless marshaller | ||
|
||
rel = request.respond_to?(:rel) ? request.rel : "" | ||
env[:body] = marshaller.marshal(payload, { :rel => rel, :recipe => env[:recipe] }) | ||
end | ||
|
||
end | ||
|
||
flow.continue(request, response, env) | ||
end | ||
|
||
protected | ||
|
||
PAYLOAD_METHODS = {:put=>true,:post=>true,:patch=>true} | ||
|
||
def should_have_payload?(method) | ||
PAYLOAD_METHODS[method] | ||
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