sevenwire-http_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +159 -0
- data/Rakefile +48 -0
- data/VERSION.yml +4 -0
- data/bin/http_client +82 -0
- data/lib/http_client.rb +93 -0
- data/lib/http_client/exceptions.rb +39 -0
- data/lib/http_client/mixin/response.rb +43 -0
- data/lib/http_client/raw_response.rb +30 -0
- data/lib/http_client/request.rb +207 -0
- data/lib/http_client/resource.rb +146 -0
- data/lib/http_client/response.rb +20 -0
- data/spec/base.rb +4 -0
- data/spec/exceptions_spec.rb +12 -0
- data/spec/http_client_spec.rb +53 -0
- data/spec/mixin/response_spec.rb +46 -0
- data/spec/raw_response_spec.rb +17 -0
- data/spec/request_spec.rb +431 -0
- data/spec/resource_spec.rb +75 -0
- data/spec/response_spec.rb +16 -0
- metadata +88 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
describe HttpClient::Resource do
|
4
|
+
before do
|
5
|
+
@resource = HttpClient::Resource.new('http://some/resource', :user => 'jane', :password => 'mypass', :headers => { 'X-Something' => '1'})
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Resource delegation" do
|
9
|
+
it "GET" do
|
10
|
+
HttpClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => { 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
11
|
+
@resource.get
|
12
|
+
end
|
13
|
+
|
14
|
+
it "POST" do
|
15
|
+
HttpClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'abc', :headers => { :content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
16
|
+
@resource.post 'abc', :content_type => 'image/jpg'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "PUT" do
|
20
|
+
HttpClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'abc', :headers => { :content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
21
|
+
@resource.put 'abc', :content_type => 'image/jpg'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "DELETE" do
|
25
|
+
HttpClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => { 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
26
|
+
@resource.delete
|
27
|
+
end
|
28
|
+
|
29
|
+
it "overrides resource headers" do
|
30
|
+
HttpClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => { 'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
|
31
|
+
@resource.get 'X-Something' => '2'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can instantiate with no user/password" do
|
36
|
+
@resource = HttpClient::Resource.new('http://some/resource')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "is backwards compatible with previous constructor" do
|
40
|
+
@resource = HttpClient::Resource.new('http://some/resource', 'user', 'pass')
|
41
|
+
@resource.user.should == 'user'
|
42
|
+
@resource.password.should == 'pass'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "concatinates urls, inserting a slash when it needs one" do
|
46
|
+
@resource.concat_urls('http://example.com', 'resource').should == 'http://example.com/resource'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "concatinates urls, using no slash if the first url ends with a slash" do
|
50
|
+
@resource.concat_urls('http://example.com/', 'resource').should == 'http://example.com/resource'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "concatinates urls, using no slash if the second url starts with a slash" do
|
54
|
+
@resource.concat_urls('http://example.com', '/resource').should == 'http://example.com/resource'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "concatinates even non-string urls, :posts + 1 => 'posts/1'" do
|
58
|
+
@resource.concat_urls(:posts, 1).should == 'posts/1'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "offers subresources via []" do
|
62
|
+
parent = HttpClient::Resource.new('http://example.com')
|
63
|
+
parent['posts'].url.should == 'http://example.com/posts'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "transports options to subresources" do
|
67
|
+
parent = HttpClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
|
68
|
+
parent['posts'].user.should == 'user'
|
69
|
+
parent['posts'].password.should == 'password'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "prints its url with to_s" do
|
73
|
+
HttpClient::Resource.new('x').to_s.should == 'x'
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
describe HttpClient::Response do
|
4
|
+
before do
|
5
|
+
@net_http_res = mock('net http response')
|
6
|
+
@response = HttpClient::Response.new('abc', @net_http_res)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "behaves like string" do
|
10
|
+
@response.should == 'abc'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
14
|
+
HttpClient::Response.new(nil, @net_http_res).should == ""
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sevenwire-http_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Adam Wiggins
|
13
|
+
- Nate Sutton
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2009-04-16 00:00:00 -04:00
|
19
|
+
default_executable: http_client
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: nate@sevenwire.com
|
24
|
+
executables:
|
25
|
+
- http_client
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- README.rdoc
|
32
|
+
- Rakefile
|
33
|
+
- VERSION.yml
|
34
|
+
- bin/http_client
|
35
|
+
- lib/http_client.rb
|
36
|
+
- lib/http_client/exceptions.rb
|
37
|
+
- lib/http_client/mixin/response.rb
|
38
|
+
- lib/http_client/raw_response.rb
|
39
|
+
- lib/http_client/request.rb
|
40
|
+
- lib/http_client/resource.rb
|
41
|
+
- lib/http_client/response.rb
|
42
|
+
- spec/base.rb
|
43
|
+
- spec/exceptions_spec.rb
|
44
|
+
- spec/http_client_spec.rb
|
45
|
+
- spec/mixin/response_spec.rb
|
46
|
+
- spec/raw_response_spec.rb
|
47
|
+
- spec/request_spec.rb
|
48
|
+
- spec/resource_spec.rb
|
49
|
+
- spec/response_spec.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/sevenwire/http_client
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 2
|
79
|
+
summary: Simple HTTP/REST client for Ruby, inspired by microframework syntax for specifying actions. Forked from RestClient http://rest-client.heroku.com see README for reasons
|
80
|
+
test_files:
|
81
|
+
- spec/base.rb
|
82
|
+
- spec/exceptions_spec.rb
|
83
|
+
- spec/http_client_spec.rb
|
84
|
+
- spec/mixin/response_spec.rb
|
85
|
+
- spec/raw_response_spec.rb
|
86
|
+
- spec/request_spec.rb
|
87
|
+
- spec/resource_spec.rb
|
88
|
+
- spec/response_spec.rb
|