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
97c7d9e
commit 2e042e6
Showing
7 changed files
with
102 additions
and
98 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,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 not shown.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -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.