curb-fu 0.6.0 → 0.6.1

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.
@@ -3,7 +3,7 @@ module CurbFu
3
3
  module Base
4
4
  include Common
5
5
 
6
- def build(url_params, query_params = {}, &block)
6
+ def build(url_params, query_params = {}, cookies = nil, &block)
7
7
  curb = Curl::Easy.new(build_url(url_params, query_params))
8
8
 
9
9
  headers = global_headers
@@ -15,11 +15,14 @@ module CurbFu
15
15
  elsif url_params[:username]
16
16
  curb.http_auth_types = CurbFu::Authentication::BASIC
17
17
  end
18
-
18
+
19
+ cookies ||= url_params[:cookies]
20
+
19
21
  headers = headers.merge(url_params[:headers]) unless url_params[:headers].nil?
20
22
  headers["Expect"] = '' unless url_params[:headers] && url_params[:headers]["Expect"]
21
23
  end
22
24
 
25
+ curb.cookies = cookies if cookies
23
26
  curb.headers = headers
24
27
  curb.timeout = @timeout
25
28
 
@@ -40,23 +43,26 @@ module CurbFu
40
43
  @global_headers ||= {}
41
44
  end
42
45
 
43
- def get(url, params = {}, &block)
44
- curb = self.build(url, params, &block)
46
+ def get(url, params = {}, cookies = nil, &block)
47
+ curb = self.build(url, params, cookies, &block)
45
48
  curb.http_get
46
49
  CurbFu::Response::Base.from_curb_response(curb)
47
50
  end
48
51
 
49
- def put(url, params = {}, &block)
50
- curb = self.build(url, params, &block)
51
- curb.http_put("")
52
+ def put(url, params = {}, cookies = nil, &block)
53
+ fields = create_post_fields(params)
54
+ fields = [fields] if fields.is_a?(String)
55
+
56
+ curb = self.build(url, {}, cookies, &block)
57
+ curb.http_put(*fields)
52
58
  CurbFu::Response::Base.from_curb_response(curb)
53
59
  end
54
60
 
55
- def post(url, params = {}, &block)
61
+ def post(url, params = {}, cookies = nil, &block)
56
62
  fields = create_post_fields(params)
57
63
  fields = [fields] if fields.is_a?(String)
58
64
 
59
- curb = self.build(url, &block)
65
+ curb = self.build(url, {}, cookies, &block)
60
66
  curb.http_post(*fields)
61
67
  response = CurbFu::Response::Base.from_curb_response(curb)
62
68
  if CurbFu.debug?
@@ -68,11 +74,11 @@ module CurbFu
68
74
  response
69
75
  end
70
76
 
71
- def post_file(url, params = {}, filez = {}, &block)
77
+ def post_file(url, params = {}, filez = {}, cookies = nil, &block)
72
78
  fields = create_post_fields(params)
73
79
  fields += create_file_fields(filez)
74
80
 
75
- curb = self.build(url, &block)
81
+ curb = self.build(url, {}, cookies, &block)
76
82
  curb.multipart_form_post = true
77
83
 
78
84
  begin
@@ -84,8 +90,8 @@ module CurbFu
84
90
  CurbFu::Response::Base.from_curb_response(curb)
85
91
  end
86
92
 
87
- def delete(url, &block)
88
- curb = self.build(url, &block)
93
+ def delete(url, cookies = nil, &block)
94
+ curb = self.build(url, {}, cookies, &block)
89
95
  curb.http_delete
90
96
  CurbFu::Response::Base.from_curb_response(curb)
91
97
  end
@@ -12,6 +12,8 @@ module CurbFu
12
12
  def build_url(url_params, query_params = {})
13
13
  if url_params.is_a? String
14
14
  built_url = url_params
15
+ elsif url_params[:url]
16
+ built_url = url_params[:url]
15
17
  else
16
18
  protocol = url_params[:protocol] || "http"
17
19
  built_url = "#{protocol}://#{url_params[:host]}"
@@ -30,6 +30,9 @@ describe CurbFu::Request::Base do
30
30
  it "should return a string if a string parameter is given" do
31
31
  TestHarness.build_url("http://www.cliffsofinsanity.com").should == "http://www.cliffsofinsanity.com"
32
32
  end
33
+ it "should return a string if a :url paramter is given" do
34
+ TestHarness.build_url(:url => "http://www.cliffsofinsanity.com", :headers => { 'Content-Type' => 'cash/dollars' }).should == "http://www.cliffsofinsanity.com"
35
+ end
33
36
  it "should return a built url with just a hostname if only the hostname is given" do
34
37
  TestHarness.build_url(:host => "poisonedwine.com").should == "http://poisonedwine.com"
35
38
  end
@@ -74,6 +77,15 @@ describe CurbFu::Request::Base do
74
77
  Curl::Easy.should_receive(:new).with(regex_for_url_with_params('http://www.google.com', 'search=MSU\+vs\+UNC', 'limit=200')).and_return(@mock_curb)
75
78
  TestHarness.get('http://www.google.com', { :search => 'MSU vs UNC', :limit => 200 })
76
79
  end
80
+ it "should set cookies" do
81
+ the_cookies = "SekretAuth=123134234"
82
+
83
+ @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil)
84
+ Curl::Easy.should_receive(:new).and_return(@mock_curb)
85
+ @mock_curb.should_receive(:cookies=).with(the_cookies)
86
+
87
+ TestHarness.get("http://google.com", {}, the_cookies)
88
+ end
77
89
 
78
90
  describe "with_hash" do
79
91
  it "should get google from {:host => \"www.google.com\", :port => 80}" do
@@ -94,6 +106,19 @@ describe CurbFu::Request::Base do
94
106
  Curl::Easy.should_receive(:new).with(regex_for_url_with_params('http://www.google.com', 'search=MSU\+vs\+UNC', 'limit=200')).and_return(@mock_curb)
95
107
  TestHarness.get({ :host => 'www.google.com' }, { :search => 'MSU vs UNC', :limit => 200 })
96
108
  end
109
+ it "should set cookies" do
110
+ the_cookies = "SekretAuth=123134234"
111
+
112
+ @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil)
113
+ Curl::Easy.should_receive(:new).and_return(@mock_curb)
114
+ @mock_curb.should_receive(:cookies=).with(the_cookies)
115
+
116
+ TestHarness.get({
117
+ :host => "google.com",
118
+ :port => 80,
119
+ :cookies => the_cookies
120
+ })
121
+ end
97
122
  end
98
123
  end
99
124
 
@@ -156,15 +181,34 @@ describe CurbFu::Request::Base do
156
181
  end
157
182
 
158
183
  it "should send each parameter to Curb#http_put" do
159
- Curl::Easy.should_receive(:new).with('http://google.com:80/search?q=derek&r=matt').and_return(@mock_curb)
160
- @mock_curb.should_receive(:http_put)
184
+ @mock_q = Curl::PostField.content('q','derek')
185
+ @mock_r = Curl::PostField.content('r','matt')
186
+ TestHarness.stub!(:create_post_fields).and_return([@mock_q,@mock_r])
161
187
 
188
+ @mock_curb.should_receive(:http_put).with(@mock_q,@mock_r)
189
+
162
190
  response = TestHarness.put(
163
191
  {:host => "google.com", :port => 80, :path => "/search"},
164
192
  { 'q' => 'derek', 'r' => 'matt' })
165
193
  end
166
194
  end
167
195
 
196
+ describe "delete" do
197
+ before(:each) do
198
+ @resource_link = 'http://example.com/resource/1'
199
+ @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil)
200
+ Curl::Easy.stub!(:new).and_return(@mock_curb)
201
+ end
202
+
203
+ it "should send each parameter to Curb#http_delete" do
204
+ Curl::Easy.should_receive(:new).with(@resource_link).and_return(@mock_curb)
205
+ @mock_curb.should_receive(:http_delete)
206
+
207
+ response = TestHarness.delete(@resource_link)
208
+ end
209
+ end
210
+
211
+
168
212
  describe "create_post_fields" do
169
213
  it "should return the params if params is a string" do
170
214
  TestHarness.create_post_fields("my awesome data that I'm sending to you").
metadata CHANGED
@@ -1,70 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: curb-fu
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
4
5
  prerelease:
5
- version: 0.6.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Derek Kastner, Matt Wilson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-11 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: curb
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152758580 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.5.4.0
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rack-test
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152758580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-test
27
+ requirement: &2152758040 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
34
32
  version: 0.2.0
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152758040
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2152757500 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
45
43
  version: 1.3.2
46
44
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: htmlentities
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2152757500
47
+ - !ruby/object:Gem::Dependency
48
+ name: htmlentities
49
+ requirement: &2152757120 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :development
58
- version_requirements: *id004
56
+ prerelease: false
57
+ version_requirements: *2152757120
59
58
  description:
60
59
  email: development@greenviewdata.com
61
60
  executables: []
62
-
63
61
  extensions: []
64
-
65
62
  extra_rdoc_files: []
66
-
67
- files:
63
+ files:
68
64
  - lib/curb-fu/authentication.rb
69
65
  - lib/curb-fu/core_ext.rb
70
66
  - lib/curb-fu/request/base.rb
@@ -88,32 +84,29 @@ files:
88
84
  - spec/spec_helper.rb
89
85
  homepage:
90
86
  licenses: []
91
-
92
87
  post_install_message:
93
88
  rdoc_options: []
94
-
95
- require_paths:
89
+ require_paths:
96
90
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
98
92
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
103
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
98
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
109
103
  requirements: []
110
-
111
104
  rubyforge_project:
112
- rubygems_version: 1.8.5
105
+ rubygems_version: 1.8.10
113
106
  signing_key:
114
107
  specification_version: 3
115
108
  summary: Friendly wrapper for curb
116
- test_files:
109
+ test_files:
117
110
  - spec/fixtures/foo.txt
118
111
  - spec/lib/curb-fu/core_ext_spec.rb
119
112
  - spec/lib/curb-fu/request/base_spec.rb