httparty 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

data/History CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.6.1
2
+ * minor enhancements
3
+ * updated to crack 0.1.8
4
+ * bug fixes
5
+ * subclasses always merge into the parent's default_options and
6
+ default_cookies (l4rk).
7
+ * subclasses play nicely with grand parents. gh-49
8
+
1
9
  == 0.6.0 2010-06-13
2
10
  * major enhancements
3
11
  * Digest Auth (bartiaco, sbecker, gilles, and aaronrussell)
data/Rakefile CHANGED
@@ -1,15 +1,19 @@
1
1
  require 'rake'
2
+ require File.expand_path('../lib/httparty', __FILE__)
2
3
 
3
4
  begin
4
5
  require 'jeweler'
5
6
  Jeweler::Tasks.new do |gem|
6
- gem.name = "httparty"
7
- gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
7
+ gem.name = "httparty"
8
+ gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
8
9
  gem.description = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
9
- gem.email = "nunemaker@gmail.com"
10
- gem.homepage = "http://httparty.rubyforge.org"
11
- gem.authors = ["John Nunemaker", "Sandro Turriate"]
12
- gem.add_dependency 'crack', '0.1.7'
10
+ gem.email = "nunemaker@gmail.com"
11
+ gem.homepage = "http://httparty.rubyforge.org"
12
+ gem.authors = ["John Nunemaker", "Sandro Turriate"]
13
+ gem.version = HTTParty::VERSION
14
+
15
+ gem.add_dependency 'crack', HTTParty::CRACK_DEPENDENCY
16
+
13
17
  gem.add_development_dependency "activesupport", "~>2.3"
14
18
  gem.add_development_dependency "cucumber", "~>0.7"
15
19
  gem.add_development_dependency "fakeweb", "~>1.2"
@@ -29,6 +33,7 @@ end
29
33
 
30
34
  require 'spec/rake/spectask'
31
35
  Spec::Rake::SpecTask.new(:spec) do |spec|
36
+ spec.ruby_opts << '-rubygems'
32
37
  spec.libs << 'lib' << 'spec'
33
38
  spec.spec_files = FileList['spec/**/*_spec.rb']
34
39
  spec.spec_opts = ['--options', 'spec/spec.opts']
@@ -5,16 +5,16 @@ Feature: Basic Authentication
5
5
  Because that is not an uncommon requirement
6
6
 
7
7
  Scenario: Passing no credentials to a page requiring Basic Authentication
8
- Given a restricted page at '/protected.html'
9
- When I call HTTParty#get with '/protected.html'
8
+ Given a restricted page at '/basic_auth.html'
9
+ When I call HTTParty#get with '/basic_auth.html'
10
10
  Then it should return a response with a 401 response code
11
11
 
12
12
  Scenario: Passing proper credentials to a page requiring Basic Authentication
13
13
  Given a remote service that returns 'Authenticated Page'
14
- And that service is accessed at the path '/protected.html'
14
+ And that service is accessed at the path '/basic_auth.html'
15
15
  And that service is protected by Basic Authentication
16
16
  And that service requires the username 'jcash' with the password 'maninblack'
17
- When I call HTTParty#get with '/protected.html' and a basic_auth hash:
17
+ When I call HTTParty#get with '/basic_auth.html' and a basic_auth hash:
18
18
  | username | password |
19
19
  | jcash | maninblack |
20
20
  Then the return value should match 'Authenticated Page'
@@ -7,20 +7,20 @@ Feature: Deals with HTTP error codes
7
7
 
8
8
  Scenario: A response of '404 - Not Found'
9
9
  Given a remote service that returns a 404 status code
10
- And that service is accessed at the path '/service.html'
11
- When I call HTTParty#get with '/service.html'
10
+ And that service is accessed at the path '/404_service.html'
11
+ When I call HTTParty#get with '/404_service.html'
12
12
  Then it should return a response with a 404 response code
13
13
 
14
14
  Scenario: A response of '500 - Internal Server Error'
15
15
  Given a remote service that returns a 500 status code
16
- And that service is accessed at the path '/service.html'
17
- When I call HTTParty#get with '/service.html'
16
+ And that service is accessed at the path '/500_service.html'
17
+ When I call HTTParty#get with '/500_service.html'
18
18
  Then it should return a response with a 500 response code
19
19
 
20
20
  Scenario: A non-successful response where I need the body
21
21
  Given a remote service that returns a 400 status code
22
22
  And the response from the service has a body of 'Bad response'
23
- And that service is accessed at the path '/service.html'
24
- When I call HTTParty#get with '/service.html'
23
+ And that service is accessed at the path '/400_service.html'
24
+ When I call HTTParty#get with '/400_service.html'
25
25
  Then it should return a response with a 400 response code
26
26
  And the return value should match 'Bad response'
@@ -5,16 +5,16 @@ Feature: Digest Authentication
5
5
  Because that is not an uncommon requirement
6
6
 
7
7
  Scenario: Passing no credentials to a page requiring Digest Authentication
8
- Given a restricted page at '/protected.html'
9
- When I call HTTParty#get with '/protected.html'
8
+ Given a restricted page at '/digest_auth.html'
9
+ When I call HTTParty#get with '/digest_auth.html'
10
10
  Then it should return a response with a 401 response code
11
11
 
12
12
  Scenario: Passing proper credentials to a page requiring Digest Authentication
13
13
  Given a remote service that returns 'Digest Authenticated Page'
14
- And that service is accessed at the path '/protected.html'
14
+ And that service is accessed at the path '/digest_auth.html'
15
15
  And that service is protected by Digest Authentication
16
16
  And that service requires the username 'jcash' with the password 'maninblack'
17
- When I call HTTParty#get with '/protected.html' and a digest_auth hash:
17
+ When I call HTTParty#get with '/digest_auth.html' and a digest_auth hash:
18
18
  | username | password |
19
19
  | jcash | maninblack |
20
20
  Then the return value should match 'Digest Authenticated Page'
@@ -7,13 +7,13 @@ Feature: Handles Compressed Responses
7
7
  Scenario: Supports deflate encoding
8
8
  Given a remote deflate service
9
9
  And the response from the service has a body of '<h1>Some HTML</h1>'
10
- And that service is accessed at the path '/service.html'
11
- When I call HTTParty#get with '/service.html'
10
+ And that service is accessed at the path '/deflate_service.html'
11
+ When I call HTTParty#get with '/deflate_service.html'
12
12
  Then the return value should match '<h1>Some HTML</h1>'
13
13
 
14
14
  Scenario: Supports gzip encoding
15
15
  Given a remote gzip service
16
16
  And the response from the service has a body of '<h1>Some HTML</h1>'
17
- And that service is accessed at the path '/service.html'
18
- When I call HTTParty#get with '/service.html'
17
+ And that service is accessed at the path '/gzip_service.html'
18
+ When I call HTTParty#get with '/gzip_service.html'
19
19
  Then the return value should match '<h1>Some HTML</h1>'
@@ -8,9 +8,9 @@ Feature: Handles Multiple Formats
8
8
 
9
9
  Scenario: An HTML service
10
10
  Given a remote service that returns '<h1>Some HTML</h1>'
11
- And that service is accessed at the path '/service.html'
11
+ And that service is accessed at the path '/html_service.html'
12
12
  And the response from the service has a Content-Type of 'text/html'
13
- When I call HTTParty#get with '/service.html'
13
+ When I call HTTParty#get with '/html_service.html'
14
14
  Then it should return a String
15
15
  And the return value should match '<h1>Some HTML</h1>'
16
16
 
@@ -1,5 +1,5 @@
1
1
  Then /it should return an? (\w+)$/ do |class_string|
2
- @response_from_httparty.should be_an_instance_of(class_string.constantize)
2
+ @response_from_httparty.should be_an_instance_of(class_string.class)
3
3
  end
4
4
 
5
5
  Then /the return value should match '(.*)'/ do |expected_text|
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  class BasicMongrelHandler < Mongrel::HttpHandler
2
3
  attr_accessor :content_type, :custom_headers, :response_body, :response_code, :preprocessor, :username, :password
3
4
 
@@ -7,8 +7,8 @@ Feature: Supports Redirection
7
7
 
8
8
  Scenario: A service that redirects once
9
9
  Given a remote service that returns 'Service Response'
10
- And that service is accessed at the path '/service.html'
11
- And the url '/redirector.html' redirects to '/service.html'
10
+ And that service is accessed at the path '/landing_service.html'
11
+ And the url '/redirector.html' redirects to '/landing_service.html'
12
12
  When I call HTTParty#get with '/redirector.html'
13
13
  Then the return value should match 'Service Response'
14
14
 
@@ -5,9 +5,9 @@ Feature: Supports the timeout option
5
5
 
6
6
  Scenario: A long running response
7
7
  Given a remote service that returns '<h1>Some HTML</h1>'
8
- And that service is accessed at the path '/service.html'
8
+ And that service is accessed at the path '/long_running_service.html'
9
9
  And that service takes 2 seconds to generate a response
10
10
  When I set my HTTParty timeout option to 1
11
- And I call HTTParty#get with '/service.html'
11
+ And I call HTTParty#get with '/long_running_service.html'
12
12
  Then it should raise a Timeout::Error exception
13
13
  And I wait for the server to recover
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{httparty}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker", "Sandro Turriate"]
12
- s.date = %q{2010-06-13}
12
+ s.date = %q{2010-07-07}
13
13
  s.default_executable = %q{httparty}
14
14
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
15
15
  s.email = %q{nunemaker@gmail.com}
@@ -105,14 +105,14 @@ Gem::Specification.new do |s|
105
105
  s.specification_version = 3
106
106
 
107
107
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
108
- s.add_runtime_dependency(%q<crack>, ["= 0.1.7"])
108
+ s.add_runtime_dependency(%q<crack>, ["= 0.1.8"])
109
109
  s.add_development_dependency(%q<activesupport>, ["~> 2.3"])
110
110
  s.add_development_dependency(%q<cucumber>, ["~> 0.7"])
111
111
  s.add_development_dependency(%q<fakeweb>, ["~> 1.2"])
112
112
  s.add_development_dependency(%q<mongrel>, ["~> 1.1"])
113
113
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
114
114
  else
115
- s.add_dependency(%q<crack>, ["= 0.1.7"])
115
+ s.add_dependency(%q<crack>, ["= 0.1.8"])
116
116
  s.add_dependency(%q<activesupport>, ["~> 2.3"])
117
117
  s.add_dependency(%q<cucumber>, ["~> 0.7"])
118
118
  s.add_dependency(%q<fakeweb>, ["~> 1.2"])
@@ -120,7 +120,7 @@ Gem::Specification.new do |s|
120
120
  s.add_dependency(%q<rspec>, ["~> 1.3"])
121
121
  end
122
122
  else
123
- s.add_dependency(%q<crack>, ["= 0.1.7"])
123
+ s.add_dependency(%q<crack>, ["= 0.1.8"])
124
124
  s.add_dependency(%q<activesupport>, ["~> 2.3"])
125
125
  s.add_dependency(%q<cucumber>, ["~> 0.7"])
126
126
  s.add_dependency(%q<fakeweb>, ["~> 1.2"])
@@ -12,8 +12,8 @@ require dir + 'httparty/cookie_hash'
12
12
  require dir + 'httparty/net_digest_auth'
13
13
 
14
14
  module HTTParty
15
- VERSION = "0.6.0".freeze
16
- CRACK_DEPENDENCY = "0.1.7".freeze
15
+ VERSION = "0.6.1".freeze
16
+ CRACK_DEPENDENCY = "0.1.8".freeze
17
17
 
18
18
  module AllowedFormatsDeprecation
19
19
  def const_missing(const)
@@ -15,9 +15,18 @@ module HTTParty
15
15
  end
16
16
 
17
17
  def inherited(subclass)
18
+ super
18
19
  @mattr_inheritable_attrs.each do |inheritable_attribute|
19
- instance_var = "@#{inheritable_attribute}"
20
- subclass.instance_variable_set(instance_var, instance_variable_get(instance_var).clone)
20
+ ivar = "@#{inheritable_attribute}"
21
+ subclass.instance_variable_set(ivar, instance_variable_get(ivar).clone)
22
+ if instance_variable_get(ivar).respond_to?(:merge)
23
+ method = <<-EOM
24
+ def self.#{inheritable_attribute}
25
+ #{ivar} = superclass.#{inheritable_attribute}.merge #{ivar}
26
+ end
27
+ EOM
28
+ subclass.class_eval method
29
+ end
21
30
  end
22
31
  end
23
32
  end
@@ -416,6 +416,9 @@ describe HTTParty do
416
416
  before(:each) do
417
417
  @parent = Class.new do
418
418
  include HTTParty
419
+ def self.name
420
+ "Parent"
421
+ end
419
422
  end
420
423
 
421
424
  @child1 = Class.new(@parent)
@@ -431,6 +434,59 @@ describe HTTParty do
431
434
 
432
435
  @parent.default_options.should == { }
433
436
  end
437
+
438
+ it "inherits default_options from the superclass" do
439
+ @parent.basic_auth 'user', 'password'
440
+ @child1.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
441
+ @child1.basic_auth 'u', 'p' # modifying child1 has no effect on child2
442
+ @child2.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
443
+ end
444
+
445
+ it "doesn't modify the parent's default options" do
446
+ @parent.basic_auth 'user', 'password'
447
+
448
+ @child1.basic_auth 'u', 'p'
449
+ @child1.default_options.should == {:basic_auth => {:username => 'u', :password => 'p'}}
450
+
451
+ @child1.basic_auth 'email', 'token'
452
+ @child1.default_options.should == {:basic_auth => {:username => 'email', :password => 'token'}}
453
+
454
+ @parent.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
455
+ end
456
+
457
+ it "inherits default_cookies from the parent class" do
458
+ @parent.cookies 'type' => 'chocolate_chip'
459
+ @child1.default_cookies.should == {"type" => "chocolate_chip"}
460
+ @child1.cookies 'type' => 'snickerdoodle'
461
+ @child1.default_cookies.should == {"type" => "snickerdoodle"}
462
+ @child2.default_cookies.should == {"type" => "chocolate_chip"}
463
+ end
464
+
465
+ it "doesn't modify the parent's default cookies" do
466
+ @parent.cookies 'type' => 'chocolate_chip'
467
+
468
+ @child1.cookies 'type' => 'snickerdoodle'
469
+ @child1.default_cookies.should == {"type" => "snickerdoodle"}
470
+
471
+ @parent.default_cookies.should == {"type" => "chocolate_chip"}
472
+ end
473
+ end
474
+
475
+ describe "grand parent with inherited callback" do
476
+ before do
477
+ @grand_parent = Class.new do
478
+ def self.inherited(subclass)
479
+ subclass.instance_variable_set(:@grand_parent, true)
480
+ end
481
+ end
482
+ @parent = Class.new(@grand_parent) do
483
+ include HTTParty
484
+ end
485
+ end
486
+ it "continues running the #inherited on the parent" do
487
+ child = Class.new(@parent)
488
+ child.instance_variable_get(:@grand_parent).should be_true
489
+ end
434
490
  end
435
491
 
436
492
  describe "#get" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 0
9
- version: 0.6.0
8
+ - 1
9
+ version: 0.6.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-13 00:00:00 -04:00
18
+ date: 2010-07-07 00:00:00 -04:00
19
19
  default_executable: httparty
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  - 1
31
- - 7
32
- version: 0.1.7
31
+ - 8
32
+ version: 0.1.8
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency