Skip to content

Commit

Permalink
moved
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 19, 2010
1 parent c7e2acd commit 024898c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 69 deletions.
3 changes: 1 addition & 2 deletions lib/restfulie/client/http/request_marshaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def request!(method, path, *args)
args = add_representation_headers(method, path, unmarshaller, *args)
end

key, req, response = delegate(:request, method, path, *args)
response
delegate(:request, method, path, *args)

end

Expand Down
67 changes: 0 additions & 67 deletions tests/spec/requests/http/adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,71 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

module Restfulie
module Client
module HTTP

class UnmarshallHandler

# parses the http response.
# first checks if its a 201, redirecting to the resource location.
# otherwise check if its a raw request, returning the content itself.
# finally, tries to parse the content with a mediatype handler or returns the response itself.
def parse(host, path, http_request, request, response)
response = @requester.parse(host, path, http_request, request, response)
if response.code == 201
request = Restfulie.at(response.headers['location'])
request.accepts(@config.acceptable_mediatypes) if @config.acceptable_mediatypes
request.get!
elsif @config.raw?
response
elsif (!response.body.nil?) && !response.body.empty?
representation = RequestMarshaller.content_type_for(response.headers['content-type']) || Restfulie::Common::Representation::Generic.new
representation.unmarshal(response.body).tap do |u|
u.extend(ResponseHolder)
u.response = response
u
end
else
response.tap do |resp|
resp.extend(ResponseHolder)
resp.response = response
resp
end
end
end
end

class RequestMarshaller < MasterDelegator

# Executes super if its a raw request, returning the content itself.
# otherwise tries to parse the content with a mediatype handler or returns the response itself.
def request!(method, path, *args)
if has_payload?(method, path, *args)
recipe = get_recipe(*args)

payload = get_payload(method, path, *args)
rel = self.respond_to?(:rel) ? self.rel : ""
type = headers['Content-Type']
raise Restfulie::Common::Error::RestfulieError, "Missing content type related to the data to be submitted" unless type
marshaller = RequestMarshaller.content_type_for(type)
payload = marshaller.marshal(payload, { :rel => rel, :recipe => recipe }) unless payload.nil? || (payload.kind_of?(String) && payload.empty?)
args = set_marshalled_payload(method, path, payload, *args)
args = add_representation_headers(method, path, marshaller, *args)
end

if @acceptable_mediatypes
unmarshaller = RequestMarshaller.content_type_for(@acceptable_mediatypes)
args = add_representation_headers(method, path, unmarshaller, *args)
end

delegate(:request, method, path, *args)

end
end
end
end
end

context Restfulie::Client::HTTP do

context "HTTP Base" do
Expand All @@ -92,7 +26,6 @@ def request!(method, path, *args)
end

it "should get! and respond 200 code" do
debugger
@client.at("/test").get!.response.code.should == 200
end

Expand Down

0 comments on commit 024898c

Please sign in to comment.