curb-fu 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/curb-fu.rb +0 -2
- data/lib/curb-fu/request/base.rb +16 -1
- data/lib/curb-fu/request/common.rb +2 -1
- data/lib/curb-fu/response.rb +45 -45
- data/spec/lib/curb-fu/request/base_spec.rb +5 -2
- data/spec/lib/curb-fu/response_spec.rb +13 -1
- metadata +31 -15
data/lib/curb-fu.rb
CHANGED
data/lib/curb-fu/request/base.rb
CHANGED
@@ -56,7 +56,14 @@ module CurbFu
|
|
56
56
|
|
57
57
|
curb = self.build(url)
|
58
58
|
curb.http_post(*fields)
|
59
|
-
CurbFu::Response::Base.from_curb_response(curb)
|
59
|
+
response = CurbFu::Response::Base.from_curb_response(curb)
|
60
|
+
if CurbFu.debug?
|
61
|
+
puts "Response from server was"
|
62
|
+
puts "Status: #{response.status}"
|
63
|
+
puts "Headers: #{response.headers.inspect}"
|
64
|
+
puts "Body: #{response.body.inspect}"
|
65
|
+
end
|
66
|
+
response
|
60
67
|
end
|
61
68
|
|
62
69
|
def post_file(url, params = {}, filez = {})
|
@@ -73,6 +80,14 @@ module CurbFu
|
|
73
80
|
raise e, "There was an attempt to post invalid fields. The fields were:\n#{field_list.join("\n")}"
|
74
81
|
end
|
75
82
|
CurbFu::Response::Base.from_curb_response(curb)
|
83
|
+
response = CurbFu::Response::Base.from_curb_response(curb)
|
84
|
+
if CurbFu.debug?
|
85
|
+
puts "Response from server was"
|
86
|
+
puts "Status: #{response.status}"
|
87
|
+
puts "Headers: #{response.headers.inspect}"
|
88
|
+
puts "Body: #{response.body.inspect}"
|
89
|
+
end
|
90
|
+
response
|
76
91
|
end
|
77
92
|
|
78
93
|
def delete(url)
|
@@ -13,7 +13,8 @@ module CurbFu
|
|
13
13
|
if url_params.is_a? String
|
14
14
|
built_url = url_params
|
15
15
|
else
|
16
|
-
|
16
|
+
protocol = url_params[:protocol] || "http"
|
17
|
+
built_url = "#{protocol}://#{url_params[:host]}"
|
17
18
|
built_url += ":" + url_params[:port].to_s if url_params[:port]
|
18
19
|
built_url += url_params[:path] if url_params[:path]
|
19
20
|
end
|
data/lib/curb-fu/response.rb
CHANGED
@@ -130,50 +130,50 @@ module CurbFu
|
|
130
130
|
end
|
131
131
|
|
132
132
|
module Information; end
|
133
|
-
module Continue;
|
134
|
-
module
|
135
|
-
module Success;
|
136
|
-
module OK;
|
137
|
-
module Created;
|
138
|
-
module Accepted;
|
139
|
-
module NonAuthoritativeInformation; end
|
140
|
-
module NoContent; end
|
141
|
-
module ResetContent; end
|
142
|
-
module PartialContent; end
|
143
|
-
module Redirection; end
|
144
|
-
module MultipleChoice; end
|
145
|
-
module MovedPermanently; end
|
146
|
-
module Found;
|
147
|
-
module SeeOther; end
|
148
|
-
module NotModified; end
|
149
|
-
module UseProxy; end
|
150
|
-
module TemporaryRedirect; end
|
151
|
-
module ClientError; end
|
152
|
-
module BadRequest; end
|
153
|
-
module Unauthorized; end
|
154
|
-
module PaymentRequired; end
|
155
|
-
module Forbidden; end
|
156
|
-
module NotFound;
|
157
|
-
module MethodNotAllowed; end
|
158
|
-
module NotAcceptable; end
|
159
|
-
module ProxyAuthenticationRequired; end
|
160
|
-
module RequestTimeOut; end
|
161
|
-
module Conflict; end
|
162
|
-
module Gone;
|
163
|
-
module LengthRequired; end
|
164
|
-
module PreconditionFailed; end
|
165
|
-
module RequestEntityTooLarge; end
|
166
|
-
module RequestURITooLong; end
|
167
|
-
module UnsupportedMediaType; end
|
168
|
-
module RequestedRangeNotSatisfiable; end
|
169
|
-
module ExpectationFailed; end
|
170
|
-
module ServerError; end
|
171
|
-
module InternalServerError;
|
172
|
-
module NotImplemented; end
|
173
|
-
module BadGateway; end
|
174
|
-
module ServiceUnavailable;
|
175
|
-
module GatewayTimeOut; end
|
176
|
-
module VersionNotSupported; end
|
177
|
-
module UnknownResponse; end
|
133
|
+
module Continue; def self.to_i; 100; end; def message; "Continue"; end; end
|
134
|
+
module SwitchProtocol; def self.to_i; 101; end; def message; "Switch Protocol"; end; end
|
135
|
+
module Success; def self.to_i; 200; end; def message; "Success"; end; end
|
136
|
+
module OK; def self.to_i; 200; end; def message; "OK"; end; end
|
137
|
+
module Created; def self.to_i; 201; end; def message; "Created"; end; end
|
138
|
+
module Accepted; def self.to_i; 202; end; def message; "Accepted"; end; end
|
139
|
+
module NonAuthoritativeInformation; def self.to_i; 203; end; def message; "Non Authoritative Information"; end; end
|
140
|
+
module NoContent; def self.to_i; 204; end; def message; "No Content"; end; end
|
141
|
+
module ResetContent; def self.to_i; 205; end; def message; "Reset Content"; end; end
|
142
|
+
module PartialContent; def self.to_i; 206; end; def message; "Partial Content"; end; end
|
143
|
+
module Redirection; def self.to_i; 300; end; def message; "Redirection"; end; end
|
144
|
+
module MultipleChoice; def self.to_i; 300; end; def message; "Multiple Choice"; end; end
|
145
|
+
module MovedPermanently; def self.to_i; 301; end; def message; "Moved Permanently"; end; end
|
146
|
+
module Found; def self.to_i; 302; end; def message; "Found"; end; end
|
147
|
+
module SeeOther; def self.to_i; 303; end; def message; "See Other"; end; end
|
148
|
+
module NotModified; def self.to_i; 304; end; def message; "Not Modified"; end; end
|
149
|
+
module UseProxy; def self.to_i; 305; end; def message; "Use Proxy"; end; end
|
150
|
+
module TemporaryRedirect; def self.to_i; 307; end; def message; "Temporary Redirect"; end; end
|
151
|
+
module ClientError; def self.to_i; 400; end; def message; "Client Error"; end; end
|
152
|
+
module BadRequest; def self.to_i; 400; end; def message; "Bad Request"; end; end
|
153
|
+
module Unauthorized; def self.to_i; 401; end; def message; "Unauthorized"; end; end
|
154
|
+
module PaymentRequired; def self.to_i; 402; end; def message; "Payment Required"; end; end
|
155
|
+
module Forbidden; def self.to_i; 403; end; def message; "Forbidden"; end; end
|
156
|
+
module NotFound; def self.to_i; 404; end; def message; "Not Found"; end; end
|
157
|
+
module MethodNotAllowed; def self.to_i; 405; end; def message; "Method Not Allowed"; end; end
|
158
|
+
module NotAcceptable; def self.to_i; 406; end; def message; "Not Acceptable"; end; end
|
159
|
+
module ProxyAuthenticationRequired; def self.to_i; 407; end; def message; "Proxy Authentication Required"; end; end
|
160
|
+
module RequestTimeOut; def self.to_i; 408; end; def message; "Request Time Out"; end; end
|
161
|
+
module Conflict; def self.to_i; 409; end; def message; "Conflict"; end; end
|
162
|
+
module Gone; def self.to_i; 410; end; def message; "Gone"; end; end
|
163
|
+
module LengthRequired; def self.to_i; 411; end; def message; "Length Required"; end; end
|
164
|
+
module PreconditionFailed; def self.to_i; 412; end; def message; "Precondition Failed"; end; end
|
165
|
+
module RequestEntityTooLarge; def self.to_i; 413; end; def message; "Request Entity Too Large"; end; end
|
166
|
+
module RequestURITooLong; def self.to_i; 414; end; def message; "Request URI Too Long"; end; end
|
167
|
+
module UnsupportedMediaType; def self.to_i; 415; end; def message; "Unsupported Media Type"; end; end
|
168
|
+
module RequestedRangeNotSatisfiable; def self.to_i; 416; end; def message; "Requested Range Not Satisfiable"; end; end
|
169
|
+
module ExpectationFailed; def self.to_i; 417; end; def message; "Expectation Failed"; end; end
|
170
|
+
module ServerError; def self.to_i; 500; end; def message; "Server Error"; end; end
|
171
|
+
module InternalServerError; def self.to_i; 500; end; def message; "Internal Server Error"; end; end
|
172
|
+
module NotImplemented; def self.to_i; 501; end; def message; "Not Implemented"; end; end
|
173
|
+
module BadGateway; def self.to_i; 502; end; def message; "Bad Gateway"; end; end
|
174
|
+
module ServiceUnavailable; def self.to_i; 503; end; def message; "Service Unavailable"; end; end
|
175
|
+
module GatewayTimeOut; def self.to_i; 504; end; def message; "Gateway Time Out"; end; end
|
176
|
+
module VersionNotSupported; def self.to_i; 505; end; def message; "Version Not Supported"; end; end
|
177
|
+
module UnknownResponse; def self.to_i; 0; end; def message; "Unknown Response"; end; end
|
178
178
|
end
|
179
179
|
end
|
@@ -49,6 +49,9 @@ describe CurbFu::Request::Base do
|
|
49
49
|
TestHarness.build_url('http://chocolatecheese.com','?nuts=true').
|
50
50
|
should == 'http://chocolatecheese.com?nuts=true'
|
51
51
|
end
|
52
|
+
it "should accept a 'protocol' parameter" do
|
53
|
+
TestHarness.build_url(:host => "mybank.com", :protocol => "https").should == "https://mybank.com"
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
57
|
describe "get" do
|
@@ -196,8 +199,8 @@ describe CurbFu::Request::Base do
|
|
196
199
|
end
|
197
200
|
|
198
201
|
it 'should handle multiple parameters' do
|
199
|
-
TestHarness.create_put_fields(:rock => 'beatles', :rap => '2pac').
|
200
|
-
should
|
202
|
+
TestHarness.create_put_fields(:rock => 'beatles', :rap => '2pac').split("&").
|
203
|
+
should include("rock=beatles","rap=2pac")
|
201
204
|
end
|
202
205
|
|
203
206
|
it "should handle params that contain arrays" do
|
@@ -54,12 +54,24 @@ describe CurbFu::Response::Base do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "response modules" do
|
57
|
-
describe "to_i" do
|
57
|
+
describe ".to_i" do
|
58
58
|
it "should return the status code represented by the module" do
|
59
59
|
CurbFu::Response::OK.to_i.should == 200
|
60
60
|
CurbFu::Response::NotFound.to_i.should == 404
|
61
61
|
end
|
62
62
|
end
|
63
|
+
describe "#message" do
|
64
|
+
it "should return a string indicating the english translation of the status code" do
|
65
|
+
r = CurbFu::Response::Base.new(200, {}, "text")
|
66
|
+
r.message.should == "OK"
|
67
|
+
r = CurbFu::Response::Base.new(404, {}, "text")
|
68
|
+
r.message.should == "Not Found"
|
69
|
+
r = CurbFu::Response::Base.new(302, {}, "text")
|
70
|
+
r.message.should == "Found"
|
71
|
+
r = CurbFu::Response::Base.new(505, {}, "text")
|
72
|
+
r.message.should == "Version Not Supported"
|
73
|
+
end
|
74
|
+
end
|
63
75
|
end
|
64
76
|
|
65
77
|
describe "parse_headers" do
|
metadata
CHANGED
@@ -1,39 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curb-fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
-
|
12
|
+
- Derek Kastner, Matt Wilson
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-06-18 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: curb
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 5
|
30
|
+
- 4
|
31
|
+
- 0
|
23
32
|
version: 0.5.4.0
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: rack-test
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
39
|
requirements:
|
31
40
|
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 2
|
45
|
+
- 0
|
33
46
|
version: 0.2.0
|
34
|
-
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
description:
|
36
|
-
email:
|
50
|
+
email: development@greenviewdata.com
|
37
51
|
executables: []
|
38
52
|
|
39
53
|
extensions: []
|
@@ -67,18 +81,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
81
|
requirements:
|
68
82
|
- - ">="
|
69
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
70
86
|
version: "0"
|
71
|
-
version:
|
72
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
88
|
requirements:
|
74
89
|
- - ">="
|
75
90
|
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
76
93
|
version: "0"
|
77
|
-
version:
|
78
94
|
requirements: []
|
79
95
|
|
80
96
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.6
|
82
98
|
signing_key:
|
83
99
|
specification_version: 3
|
84
100
|
summary: Friendly wrapper for curb
|