httparty 0.8.0 → 0.8.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.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- data/examples/crack.rb +19 -0
- data/lib/httparty/request.rb +2 -1
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/request_spec.rb +26 -0
- metadata +5 -4
    
        data/examples/crack.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
            require 'crack'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
         | 
| 5 | 
            +
            require File.join(dir, 'httparty')
         | 
| 6 | 
            +
            require 'pp'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            class Rep
         | 
| 9 | 
            +
              include HTTParty
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              parser(
         | 
| 12 | 
            +
                Proc.new do |body, format|
         | 
| 13 | 
            +
                  Crack::XML.parse(body)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              )
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
         | 
| 19 | 
            +
            pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})
         | 
    
        data/lib/httparty/request.rb
    CHANGED
    
    | @@ -180,7 +180,6 @@ module HTTParty | |
| 180 180 | 
             
                  query_string_parts.size > 0 ? query_string_parts.join('&') : nil
         | 
| 181 181 | 
             
                end
         | 
| 182 182 |  | 
| 183 | 
            -
                # Raises exception Net::XXX (http error code) if an http error occured
         | 
| 184 183 | 
             
                def handle_response
         | 
| 185 184 | 
             
                  if response_redirects?
         | 
| 186 185 | 
             
                    options[:limit] -= 1
         | 
| @@ -200,8 +199,10 @@ module HTTParty | |
| 200 199 | 
             
                  when "gzip"
         | 
| 201 200 | 
             
                    body_io = StringIO.new(last_response.body)
         | 
| 202 201 | 
             
                    last_response.body.replace Zlib::GzipReader.new(body_io).read
         | 
| 202 | 
            +
                    last_response.delete('content-encoding')
         | 
| 203 203 | 
             
                  when "deflate"
         | 
| 204 204 | 
             
                    last_response.body.replace Zlib::Inflate.inflate(last_response.body)
         | 
| 205 | 
            +
                    last_response.delete('content-encoding')
         | 
| 205 206 | 
             
                  end
         | 
| 206 207 | 
             
                end
         | 
| 207 208 |  | 
    
        data/lib/httparty/version.rb
    CHANGED
    
    
| @@ -487,6 +487,32 @@ describe HTTParty::Request do | |
| 487 487 | 
             
                end
         | 
| 488 488 | 
             
              end
         | 
| 489 489 |  | 
| 490 | 
            +
              describe "#handle_deflation" do
         | 
| 491 | 
            +
                context "context-encoding" do
         | 
| 492 | 
            +
                  before do
         | 
| 493 | 
            +
                    @request.options[:format] = :html
         | 
| 494 | 
            +
                    @last_response = mock()
         | 
| 495 | 
            +
                    @last_response.stub!(:body).and_return('')
         | 
| 496 | 
            +
                  end
         | 
| 497 | 
            +
             | 
| 498 | 
            +
                  it "should inflate the gzipped body" do
         | 
| 499 | 
            +
                    @last_response.stub!(:[]).with("content-encoding").and_return("gzip")
         | 
| 500 | 
            +
                    @request.stub!(:last_response).and_return(@last_response)
         | 
| 501 | 
            +
                    Zlib::GzipReader.should_receive(:new).and_return(StringIO.new(''))
         | 
| 502 | 
            +
                    @request.last_response.should_receive(:delete).with('content-encoding')
         | 
| 503 | 
            +
                    @request.send(:handle_deflation)
         | 
| 504 | 
            +
                  end
         | 
| 505 | 
            +
             | 
| 506 | 
            +
                  it "should inflate the deflated body" do
         | 
| 507 | 
            +
                    @last_response.stub!(:[]).with("content-encoding").and_return("deflate")
         | 
| 508 | 
            +
                    @request.stub!(:last_response).and_return(@last_response)
         | 
| 509 | 
            +
                    Zlib::Inflate.should_receive(:inflate).and_return('')
         | 
| 510 | 
            +
                    @request.last_response.should_receive(:delete).with('content-encoding')
         | 
| 511 | 
            +
                    @request.send(:handle_deflation)
         | 
| 512 | 
            +
                  end
         | 
| 513 | 
            +
                end
         | 
| 514 | 
            +
              end
         | 
| 515 | 
            +
             | 
| 490 516 | 
             
              context "with POST http method" do
         | 
| 491 517 | 
             
                it "should raise argument error if query is not a hash" do
         | 
| 492 518 | 
             
                  lambda {
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: httparty
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 61
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 8
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.8. | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 0.8.1
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - John Nunemaker
         | 
| @@ -16,7 +16,7 @@ autorequire: | |
| 16 16 | 
             
            bindir: bin
         | 
| 17 17 | 
             
            cert_chain: []
         | 
| 18 18 |  | 
| 19 | 
            -
            date: 2011- | 
| 19 | 
            +
            date: 2011-10-05 00:00:00 Z
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 22 22 | 
             
              name: multi_json
         | 
| @@ -66,6 +66,7 @@ files: | |
| 66 66 | 
             
            - cucumber.yml
         | 
| 67 67 | 
             
            - examples/aaws.rb
         | 
| 68 68 | 
             
            - examples/basic.rb
         | 
| 69 | 
            +
            - examples/crack.rb
         | 
| 69 70 | 
             
            - examples/custom_parsers.rb
         | 
| 70 71 | 
             
            - examples/delicious.rb
         | 
| 71 72 | 
             
            - examples/google.rb
         |