Skip to content

Commit

Permalink
moving base file
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 21, 2010
1 parent 97c7d9e commit 2e042e6
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 98 deletions.
97 changes: 1 addition & 96 deletions lib/restfulie/client/feature.rb
@@ -1,107 +1,12 @@
module Restfulie::Client
module Feature
autoload :EnhanceResponse, 'restfulie/client/feature/enhance_response'
autoload :Base, 'restfulie/client/feature/base'
end
end

module Restfulie::Client::Feature

module Base

attr_reader :default_headers

def cookies
@cookies
end

def verb
@method
end

def get
@method = :get
request_flow
end

#Set host
def at(url)
if self.host.nil?
self.host= url
else
self.host= self.host + url
end
self
end

#Set Content-Type and Accept headers
def as(content_type)
headers['Content-Type'] = content_type
accepts(content_type)
end

#Set Accept headers
def accepts(content_type)
headers['Accept'] = content_type
self
end

# Merge internal header
#
# * <tt>headers (e.g. {'Cache-control' => 'no-cache'})</tt>
#
def with(headers)
headers.merge!(headers)
self
end

# Path (e.g. http://restfulie.com/posts => /posts)
def path
host.path
end

def host
@host
end

def host=(host)
if host.is_a?(::URI)
@host = host
else
@host = ::URI.parse(host)
end
end

def default_headers
@default_headers ||= {}
end

def headers
@headers ||= {}
end

def http_to_s(method, path, *args)
result = ["#{method.to_s.upcase} #{path}"]

arguments = args.dup
headers = arguments.extract_options!

if [:post, :put].include?(method)
body = arguments.shift
end

result << headers.collect { |key, value| "#{key}: #{value}" }.join("\n")

(result + [body ? (body.inspect + "\n") : nil]).compact.join("\n") << "\n"
end

protected

def headers=(h)
@headers = h
end

end

class BaseRequest

def execute(flow, request, response)
Expand Down
97 changes: 97 additions & 0 deletions lib/restfulie/client/feature/base.rb
@@ -0,0 +1,97 @@
module Restfulie::Client::Feature
module Base

attr_reader :default_headers

def cookies
@cookies
end

def verb
@method
end

def get
@method = :get
request_flow
end

#Set host
def at(url)
if self.host.nil?
self.host= url
else
self.host= self.host + url
end
self
end

#Set Content-Type and Accept headers
def as(content_type)
headers['Content-Type'] = content_type
accepts(content_type)
end

#Set Accept headers
def accepts(content_type)
headers['Accept'] = content_type
self
end

# Merge internal header
#
# * <tt>headers (e.g. {'Cache-control' => 'no-cache'})</tt>
#
def with(headers)
headers.merge!(headers)
self
end

# Path (e.g. http://restfulie.com/posts => /posts)
def path
host.path
end

def host
@host
end

def host=(host)
if host.is_a?(::URI)
@host = host
else
@host = ::URI.parse(host)
end
end

def default_headers
@default_headers ||= {}
end

def headers
@headers ||= {}
end

def http_to_s(method, path, *args)
result = ["#{method.to_s.upcase} #{path}"]

arguments = args.dup
headers = arguments.extract_options!

if [:post, :put].include?(method)
body = arguments.shift
end

result << headers.collect { |key, value| "#{key}: #{value}" }.join("\n")

(result + [body ? (body.inspect + "\n") : nil]).compact.join("\n") << "\n"
end

protected

def headers=(h)
@headers = h
end

end
end
Binary file removed restfulie-0.9.3.gem
Binary file not shown.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions tests/spec/requests/http/builder_spec.rb
@@ -1,12 +1,14 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

context Restfulie::Client::HTTP::VerbRequest do
context Restfulie do

context "chaining requests" do
it "should accept parameters in get requests" do
@result = Restfulie::Client::EntryPoint.at('http://localhost:4567/request_with_querystring').get!(:foo => "bar", :bar => "foo")
@result = Restfulie.at('http://localhost:4567/request_with_querystring').get(:foo => "bar", :bar => "foo")
params = JSON.parse(@result)
params["foo"].should == "bar"
params["bar"].should == "foo"
end
end

end
File renamed without changes.

0 comments on commit 2e042e6

Please sign in to comment.