Skip to content

Commit

Permalink
supporting options on flow
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 21, 2010
1 parent f06d790 commit 49893b7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
6 changes: 2 additions & 4 deletions lib/restfulie/client/dsl.rb
Expand Up @@ -30,9 +30,8 @@ def method_missing(sym, *args)
trait sym
end

def request_flow
http_response = Parser.new(@requests).continue(self, nil)
# response = Parser.new(@responses).continue(self, http_response)
def request_flow(env = {})
Parser.new(@requests).continue(self, nil, env)
end

end
Expand All @@ -51,7 +50,6 @@ def continue(*args)
end
@following = @stack.shift
filter = current.new
# debugger
filter.execute(self, *args)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/restfulie/client/feature.rb
Expand Up @@ -10,15 +10,15 @@ module Restfulie::Client::Feature

class BaseRequest

def execute(flow, request, response)
request!(request.verb, request.host, request.path, request, flow)
def execute(flow, request, response, env)
request!(request.verb, request.host, request.path, request, flow, env)
end

# Executes a request against your server and return a response instance.
# * <tt>method: :get,:post,:delete,:head,:put</tt>
# * <tt>path: '/posts'</tt>
# * <tt>args: payload: 'some text' and/or headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def request!(method, host, path, request, flow, *args)
def request!(method, host, path, request, flow, env, *args)
headers = request.default_headers.merge(args.extract_options!)
unless host.user.blank? && host.password.blank?
headers["Authorization"] = "Basic " + ["#{host.user}:#{host.password}"].pack("m").delete("\r\n")
Expand All @@ -39,7 +39,7 @@ def request!(method, host, path, request, flow, *args)
response = e
end

flow.continue(request, response)
flow.continue(request, response, env)

# Restfulie::Client::Response::EnhanceResponse.new(response_handler).parse(host, path, http_request, self, response, method)

Expand Down
2 changes: 1 addition & 1 deletion lib/restfulie/client/feature/enhance_response.rb
@@ -1,6 +1,6 @@
module Restfulie::Client::Feature
class EnhanceResponse
def execute(flow, request, response)
def execute(flow, request, response, env)
resp = flow.continue(flow, request, response)
unless resp.kind_of? ::Restfulie::Client::HTTP::ResponseHolder
resp.extend(::Restfulie::Client::HTTP::ResponseHolder)
Expand Down
16 changes: 11 additions & 5 deletions lib/restfulie/client/feature/verb.rb
Expand Up @@ -30,15 +30,17 @@ def post(payload, options = {:recipe => nil})
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def patch(payload)
request(:patch, path, payload, headers)
@verb = :patch
request_flow :payload => payload
end

# PUT HTTP verb without {Error}
# * <tt>path: '/posts'</tt>
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def put(payload)
request(:put, path, payload, headers)
@verb = :head
request_flow :payload => payload
end

# DELETE HTTP verb without {Error}
Expand All @@ -53,7 +55,9 @@ def delete
# * <tt>path: '/posts'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def get!(params = {})
request!(:get, add_query_string(path, params), headers)
@verb = :get!
at query_string(params)
request_flow
end

# HEAD HTTP verb {Error}
Expand All @@ -77,15 +81,17 @@ def post!(payload, options = {:recipe => nil})
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def patch!(payload)
request!(:patch, path, payload, headers)
@verb = :patch!
request_flow :payload => payload
end

# PUT HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def put!(payload)
request!(:put, path, payload, headers)
@verb = :put!
request_flow :payload => payload
end

# DELETE HTTP verb {Error}
Expand Down

0 comments on commit 49893b7

Please sign in to comment.