rest-client 0.3 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/rest_client.rb +13 -1
- data/spec/rest_client_spec.rb +13 -0
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/rest_client.rb
CHANGED
@@ -11,6 +11,9 @@ module RestClient
|
|
11
11
|
:headers => headers)
|
12
12
|
end
|
13
13
|
|
14
|
+
# Payload can either be a string or a hash. If it is a hash, your
|
15
|
+
# content-type will be set to www-form-urlencoded and the parameters
|
16
|
+
# converted to a CGI encoded string.
|
14
17
|
def self.post(url, payload, headers={})
|
15
18
|
Request.execute(:method => :post,
|
16
19
|
:url => url,
|
@@ -42,8 +45,8 @@ module RestClient
|
|
42
45
|
def initialize(args)
|
43
46
|
@method = args[:method] or raise ArgumentError, "must pass :method"
|
44
47
|
@url = args[:url] or raise ArgumentError, "must pass :url"
|
45
|
-
@payload = args[:payload]
|
46
48
|
@headers = args[:headers] || {}
|
49
|
+
@payload = process_payload(args[:payload])
|
47
50
|
@user = args[:user]
|
48
51
|
@password = args[:password]
|
49
52
|
end
|
@@ -87,6 +90,15 @@ module RestClient
|
|
87
90
|
# Authorization is required to access the resource specified.
|
88
91
|
class Unauthorized < Exception; end
|
89
92
|
|
93
|
+
def process_payload(p=nil)
|
94
|
+
unless p.is_a?(Hash)
|
95
|
+
p
|
96
|
+
else
|
97
|
+
@headers[:content_type] = 'application/x-www-form-urlencoded'
|
98
|
+
p.keys.map { |k| "#{k}=#{URI.escape(p[k].to_s)}" }.join("&")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
90
102
|
def transmit(uri, req, payload)
|
91
103
|
setup_credentials(req)
|
92
104
|
|
data/spec/rest_client_spec.rb
CHANGED
@@ -98,6 +98,19 @@ describe RestClient do
|
|
98
98
|
@request.transmit(@uri, 'req', nil)
|
99
99
|
end
|
100
100
|
|
101
|
+
it "passes non-hash payloads straight through" do
|
102
|
+
@request.process_payload("x").should == "x"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "converts a hash payload to urlencoded data" do
|
106
|
+
@request.process_payload(:a => 'b c').should == "a=b%20c"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "set urlencoded content_type header on hash payloads" do
|
110
|
+
@request.process_payload(:a => 1)
|
111
|
+
@request.headers[:content_type].should == 'application/x-www-form-urlencoded'
|
112
|
+
end
|
113
|
+
|
101
114
|
it "sets up the credentials prior to the request" do
|
102
115
|
http = mock("net::http connection")
|
103
116
|
Net::HTTP.should_receive(:start).and_yield(http)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-04-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,8 +23,8 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- Rakefile
|
26
|
-
- lib/rest_client.rb
|
27
26
|
- lib/resource.rb
|
27
|
+
- lib/rest_client.rb
|
28
28
|
- spec/resource_spec.rb
|
29
29
|
- spec/rest_client_spec.rb
|
30
30
|
- spec/base.rb
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements: []
|
51
51
|
|
52
52
|
rubyforge_project: rest-client
|
53
|
-
rubygems_version: 1.0.
|
53
|
+
rubygems_version: 1.0.0
|
54
54
|
signing_key:
|
55
55
|
specification_version: 2
|
56
56
|
summary: Simple REST client for Ruby, inspired by microframework syntax for specifying actions.
|