httparty 0.12.0 → 0.13.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/bin/httparty +4 -1
- data/features/handles_multiple_formats.feature +15 -0
- data/features/steps/httparty_response_steps.rb +5 -0
- data/features/steps/remote_service_steps.rb +5 -0
- data/lib/httparty.rb +21 -2
- data/lib/httparty/connection_adapter.rb +8 -0
- data/lib/httparty/exceptions.rb +6 -3
- data/lib/httparty/net_digest_auth.rb +2 -2
- data/lib/httparty/parser.rb +9 -2
- data/lib/httparty/request.rb +3 -2
- data/lib/httparty/response.rb +2 -2
- data/lib/httparty/response/headers.rb +2 -2
- data/lib/httparty/version.rb +1 -1
- data/spec/fixtures/twitter.csv +2 -0
- data/spec/httparty/connection_adapter_spec.rb +42 -0
- data/spec/httparty/exception_spec.rb +23 -0
- data/spec/httparty/net_digest_auth_spec.rb +37 -0
- data/spec/httparty/parser_spec.rb +5 -0
- data/spec/httparty/request_spec.rb +32 -2
- data/spec/httparty_spec.rb +34 -3
- data/spec/spec_helper.rb +1 -0
- metadata +6 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e2e263bc6000ec32578c99ef814398a9742be7a7
         | 
| 4 | 
            +
              data.tar.gz: 9f8eb0a8ddb0100669e3f08c86fbde96b7c538d7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4e02f9c9aab76af35b66bc0421d7322357a3a180f55cb50434259ce907d9cb536adaef681312fdee37648d8b558731c1c003d5bb57caa0000a187d24377449b3
         | 
| 7 | 
            +
              data.tar.gz: 39286a8c98a2375f4fa60c98fb0ec3a5dd8828760029fcdefa054acce0da38cc20eb113cfbb6759a6df3f7ffaf7a9d62021c17ddb599318cf557ab70fdfedfad
         | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/bin/httparty
    CHANGED
    
    | @@ -18,7 +18,7 @@ OptionParser.new do |o| | |
| 18 18 | 
             
              o.on("-f",
         | 
| 19 19 | 
             
                   "--format [FORMAT]",
         | 
| 20 20 | 
             
                   "Output format to use instead of pretty-print ruby: " +
         | 
| 21 | 
            -
                   "plain, json or xml") do |f|
         | 
| 21 | 
            +
                   "plain, csv, json or xml") do |f|
         | 
| 22 22 | 
             
                opts[:output_format] = f.downcase.to_sym
         | 
| 23 23 | 
             
              end
         | 
| 24 24 |  | 
| @@ -107,6 +107,9 @@ else | |
| 107 107 | 
             
                  require 'rexml/document'
         | 
| 108 108 | 
             
                  REXML::Document.new(response.body).write(STDOUT, 2)
         | 
| 109 109 | 
             
                  puts
         | 
| 110 | 
            +
                when :csv
         | 
| 111 | 
            +
                  require 'csv'
         | 
| 112 | 
            +
                  puts CSV.parse(response.body).map{|row| row.to_s }
         | 
| 110 113 | 
             
                else
         | 
| 111 114 | 
             
                  puts response
         | 
| 112 115 | 
             
              end
         | 
| @@ -14,6 +14,21 @@ Feature: Handles Multiple Formats | |
| 14 14 | 
             
                Then it should return a String
         | 
| 15 15 | 
             
                And the return value should match '<h1>Some HTML</h1>'
         | 
| 16 16 |  | 
| 17 | 
            +
              Scenario: A CSV service
         | 
| 18 | 
            +
                Given a remote service that returns:
         | 
| 19 | 
            +
                  """
         | 
| 20 | 
            +
                  "Last Name","Name"
         | 
| 21 | 
            +
                  "jennings","waylon"
         | 
| 22 | 
            +
                  "cash","johnny"
         | 
| 23 | 
            +
                  """
         | 
| 24 | 
            +
                And that service is accessed at the path '/service.csv'
         | 
| 25 | 
            +
                And the response from the service has a Content-Type of 'application/csv'
         | 
| 26 | 
            +
                When I call HTTParty#get with '/service.csv'
         | 
| 27 | 
            +
                Then it should return an Array equaling:
         | 
| 28 | 
            +
                  | Last Name | Name   |
         | 
| 29 | 
            +
                  | jennings  | waylon |
         | 
| 30 | 
            +
                  | cash      | johnny |
         | 
| 31 | 
            +
             | 
| 17 32 | 
             
              Scenario: A JSON service
         | 
| 18 33 | 
             
                Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
         | 
| 19 34 | 
             
                And that service is accessed at the path '/service.json'
         | 
| @@ -29,6 +29,11 @@ Then /it should return a Hash equaling:/ do |hash_table| | |
| 29 29 | 
             
              end
         | 
| 30 30 | 
             
            end
         | 
| 31 31 |  | 
| 32 | 
            +
            Then /it should return an Array equaling:/ do |array|
         | 
| 33 | 
            +
              @response_from_httparty.should be_an_instance_of(Array)
         | 
| 34 | 
            +
              @response_from_httparty.should eql array.raw
         | 
| 35 | 
            +
            end
         | 
| 36 | 
            +
             | 
| 32 37 | 
             
            Then /it should return a response with a (\d+) response code/ do |code|
         | 
| 33 38 | 
             
              @response_from_httparty.code.should eql(code.to_i)
         | 
| 34 39 | 
             
            end
         | 
| @@ -3,6 +3,11 @@ Given /a remote service that returns '(.*)'/ do |response_body| | |
| 3 3 | 
             
              Given "the response from the service has a body of '#{response_body}'"
         | 
| 4 4 | 
             
            end
         | 
| 5 5 |  | 
| 6 | 
            +
            Given /^a remote service that returns:$/ do |response_body|
         | 
| 7 | 
            +
              @handler = BasicMongrelHandler.new
         | 
| 8 | 
            +
              @handler.response_body = response_body
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
             | 
| 6 11 | 
             
            Given /a remote service that returns a (\d+) status code/ do |code|
         | 
| 7 12 | 
             
              @handler = BasicMongrelHandler.new
         | 
| 8 13 | 
             
              @handler.response_code = code
         | 
    
        data/lib/httparty.rb
    CHANGED
    
    | @@ -5,6 +5,7 @@ require 'uri' | |
| 5 5 | 
             
            require 'zlib'
         | 
| 6 6 | 
             
            require 'multi_xml'
         | 
| 7 7 | 
             
            require 'json'
         | 
| 8 | 
            +
            require 'csv'
         | 
| 8 9 |  | 
| 9 10 | 
             
            require 'httparty/module_inheritable_attributes'
         | 
| 10 11 | 
             
            require 'httparty/cookie_hash'
         | 
| @@ -282,6 +283,17 @@ module HTTParty | |
| 282 283 | 
             
                  default_options[:pem_password] = password
         | 
| 283 284 | 
             
                end
         | 
| 284 285 |  | 
| 286 | 
            +
                # Allows setting a PKCS12 file to be used
         | 
| 287 | 
            +
                #
         | 
| 288 | 
            +
                #   class Foo
         | 
| 289 | 
            +
                #     include HTTParty
         | 
| 290 | 
            +
                #     pkcs12 File.read('/home/user/my.p12'), "password"
         | 
| 291 | 
            +
                #   end
         | 
| 292 | 
            +
                def pkcs12(p12_contents, password)
         | 
| 293 | 
            +
                  default_options[:p12] = p12_contents
         | 
| 294 | 
            +
                  default_options[:p12_password] = password
         | 
| 295 | 
            +
                end
         | 
| 296 | 
            +
             | 
| 285 297 | 
             
                # Override the way query strings are normalized.
         | 
| 286 298 | 
             
                # Helpful for overriding the default rails normalization of Array queries.
         | 
| 287 299 | 
             
                #
         | 
| @@ -481,11 +493,18 @@ module HTTParty | |
| 481 493 | 
             
                private
         | 
| 482 494 |  | 
| 483 495 | 
             
                  def perform_request(http_method, path, options, &block) #:nodoc:
         | 
| 484 | 
            -
                    options = default_options. | 
| 496 | 
            +
                    options = default_options.merge(options)
         | 
| 497 | 
            +
                    process_headers(options)
         | 
| 485 498 | 
             
                    process_cookies(options)
         | 
| 486 499 | 
             
                    Request.new(http_method, path, options).perform(&block)
         | 
| 487 500 | 
             
                  end
         | 
| 488 501 |  | 
| 502 | 
            +
                  def process_headers(options)
         | 
| 503 | 
            +
                    if options[:headers] && headers.any?
         | 
| 504 | 
            +
                      options[:headers] = headers.merge(options[:headers])
         | 
| 505 | 
            +
                    end
         | 
| 506 | 
            +
                  end
         | 
| 507 | 
            +
             | 
| 489 508 | 
             
                  def process_cookies(options) #:nodoc:
         | 
| 490 509 | 
             
                    return unless options[:cookies] || default_cookies.any?
         | 
| 491 510 | 
             
                    options[:headers] ||= headers.dup
         | 
| @@ -539,7 +558,7 @@ module HTTParty | |
| 539 558 | 
             
              end
         | 
| 540 559 |  | 
| 541 560 | 
             
              def self.copy(*args, &block)
         | 
| 542 | 
            -
                Basement. | 
| 561 | 
            +
                Basement.copy(*args, &block)
         | 
| 543 562 | 
             
              end
         | 
| 544 563 |  | 
| 545 564 | 
             
              def self.head(*args, &block)
         | 
| @@ -147,6 +147,14 @@ module HTTParty | |
| 147 147 | 
             
                      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
         | 
| 148 148 | 
             
                    end
         | 
| 149 149 |  | 
| 150 | 
            +
                    # PKCS12 client certificate authentication
         | 
| 151 | 
            +
                    if options[:p12]
         | 
| 152 | 
            +
                      p12 = OpenSSL::PKCS12.new(options[:p12], options[:p12_password])
         | 
| 153 | 
            +
                      http.cert = p12.certificate
         | 
| 154 | 
            +
                      http.key = p12.key
         | 
| 155 | 
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
         | 
| 156 | 
            +
                    end
         | 
| 157 | 
            +
             | 
| 150 158 | 
             
                    # SSL certificate authority file and/or directory
         | 
| 151 159 | 
             
                    if options[:ssl_ca_file]
         | 
| 152 160 | 
             
                      http.ca_file = options[:ssl_ca_file]
         | 
    
        data/lib/httparty/exceptions.rb
    CHANGED
    
    | @@ -1,13 +1,16 @@ | |
| 1 1 | 
             
            module HTTParty
         | 
| 2 | 
            +
              # @abstact Exceptions raised by HTTParty inherit from Error
         | 
| 3 | 
            +
              class Error < StandardError; end
         | 
| 4 | 
            +
             | 
| 2 5 | 
             
              # Exception raised when you attempt to set a non-existant format
         | 
| 3 | 
            -
              class UnsupportedFormat <  | 
| 6 | 
            +
              class UnsupportedFormat < Error; end
         | 
| 4 7 |  | 
| 5 8 | 
             
              # Exception raised when using a URI scheme other than HTTP or HTTPS
         | 
| 6 | 
            -
              class UnsupportedURIScheme <  | 
| 9 | 
            +
              class UnsupportedURIScheme < Error; end
         | 
| 7 10 |  | 
| 8 11 | 
             
              # @abstract Exceptions which inherit from ResponseError contain the Net::HTTP
         | 
| 9 12 | 
             
              # response object accessible via the {#response} method.
         | 
| 10 | 
            -
              class ResponseError <  | 
| 13 | 
            +
              class ResponseError < Error
         | 
| 11 14 | 
             
                # Returns the response of the last request
         | 
| 12 15 | 
             
                # @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g.
         | 
| 13 16 | 
             
                # Net::HTTPOK
         | 
| @@ -44,9 +44,9 @@ module Net | |
| 44 44 | 
             
                private
         | 
| 45 45 |  | 
| 46 46 | 
             
                  def parse(response_header)
         | 
| 47 | 
            -
                    response_header['www-authenticate'] =~  | 
| 47 | 
            +
                    response_header['www-authenticate'] =~ /Digest (.*)/
         | 
| 48 48 | 
             
                    params = {}
         | 
| 49 | 
            -
                    $ | 
| 49 | 
            +
                    $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
         | 
| 50 50 | 
             
                    params
         | 
| 51 51 | 
             
                  end
         | 
| 52 52 |  | 
    
        data/lib/httparty/parser.rb
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 1 | 
             
            module HTTParty
         | 
| 2 | 
            -
              # The default parser used by HTTParty, supports xml, json, html, and
         | 
| 2 | 
            +
              # The default parser used by HTTParty, supports xml, json, html, csv and
         | 
| 3 3 | 
             
              # plain text.
         | 
| 4 4 | 
             
              #
         | 
| 5 5 | 
             
              # == Custom Parsers
         | 
| @@ -45,7 +45,10 @@ module HTTParty | |
| 45 45 | 
             
                  'application/javascript' => :plain,
         | 
| 46 46 | 
             
                  'text/javascript'        => :plain,
         | 
| 47 47 | 
             
                  'text/html'              => :html,
         | 
| 48 | 
            -
                  'text/plain'             => :plain
         | 
| 48 | 
            +
                  'text/plain'             => :plain,
         | 
| 49 | 
            +
                  'text/csv'               => :csv,
         | 
| 50 | 
            +
                  'application/csv'        => :csv,
         | 
| 51 | 
            +
                  'text/comma-separated-values' => :csv
         | 
| 49 52 | 
             
                }
         | 
| 50 53 |  | 
| 51 54 | 
             
                # The response body of the request
         | 
| @@ -113,6 +116,10 @@ module HTTParty | |
| 113 116 | 
             
                  JSON.load(body, nil)
         | 
| 114 117 | 
             
                end
         | 
| 115 118 |  | 
| 119 | 
            +
                def csv
         | 
| 120 | 
            +
                  CSV.parse(body)
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
             | 
| 116 123 | 
             
                def html
         | 
| 117 124 | 
             
                  body
         | 
| 118 125 | 
             
                end
         | 
    
        data/lib/httparty/request.rb
    CHANGED
    
    | @@ -15,7 +15,7 @@ module HTTParty | |
| 15 15 | 
             
                SupportedURISchemes  = [URI::HTTP, URI::HTTPS, URI::Generic]
         | 
| 16 16 |  | 
| 17 17 | 
             
                NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
         | 
| 18 | 
            -
                  Array(query).map do |key, value|
         | 
| 18 | 
            +
                  Array(query).sort_by { |a| a[0].to_s }.map do |key, value|
         | 
| 19 19 | 
             
                    if value.nil?
         | 
| 20 20 | 
             
                      key.to_s
         | 
| 21 21 | 
             
                    elsif value.is_a?(Array)
         | 
| @@ -23,7 +23,7 @@ module HTTParty | |
| 23 23 | 
             
                    else
         | 
| 24 24 | 
             
                      HashConversions.to_params(key => value)
         | 
| 25 25 | 
             
                    end
         | 
| 26 | 
            -
                  end.flatten. | 
| 26 | 
            +
                  end.flatten.join('&')
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
         | 
| @@ -174,6 +174,7 @@ module HTTParty | |
| 174 174 | 
             
                    query_string_parts << options[:query] unless options[:query].nil?
         | 
| 175 175 | 
             
                  end
         | 
| 176 176 |  | 
| 177 | 
            +
                  query_string_parts.reject!(&:empty?) unless query_string_parts == [""]
         | 
| 177 178 | 
             
                  query_string_parts.size > 0 ? query_string_parts.join('&') : nil
         | 
| 178 179 | 
             
                end
         | 
| 179 180 |  | 
    
        data/lib/httparty/response.rb
    CHANGED
    
    | @@ -50,9 +50,9 @@ module HTTParty | |
| 50 50 | 
             
                  alias_method :multiple_choice?, :multiple_choices?
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 | 
            -
                def respond_to?(name)
         | 
| 53 | 
            +
                def respond_to?(name, include_all = false)
         | 
| 54 54 | 
             
                  return true if [:request, :response, :parsed_response, :body, :headers].include?(name)
         | 
| 55 | 
            -
                  parsed_response.respond_to?(name) || response.respond_to?(name)
         | 
| 55 | 
            +
                  parsed_response.respond_to?(name, include_all) || response.respond_to?(name, include_all)
         | 
| 56 56 | 
             
                end
         | 
| 57 57 |  | 
| 58 58 | 
             
                protected
         | 
    
        data/lib/httparty/version.rb
    CHANGED
    
    
| @@ -251,6 +251,48 @@ describe HTTParty::ConnectionAdapter do | |
| 251 251 | 
             
                      end
         | 
| 252 252 | 
             
                    end
         | 
| 253 253 | 
             
                  end
         | 
| 254 | 
            +
             | 
| 255 | 
            +
                  context "when providing PKCS12 certificates" do
         | 
| 256 | 
            +
                    let(:p12) { :p12_contents }
         | 
| 257 | 
            +
                    let(:options) { {:p12 => p12, :p12_password => "password"} }
         | 
| 258 | 
            +
             | 
| 259 | 
            +
                    context "when scheme is https" do
         | 
| 260 | 
            +
                      let(:uri) { URI 'https://google.com' }
         | 
| 261 | 
            +
                      let(:pkcs12) { mock("OpenSSL::PKCS12", :certificate => cert, :key => key) }
         | 
| 262 | 
            +
                      let(:cert) { mock("OpenSSL::X509::Certificate") }
         | 
| 263 | 
            +
                      let(:key) { mock("OpenSSL::PKey::RSA") }
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                      before do
         | 
| 266 | 
            +
                        OpenSSL::PKCS12.should_receive(:new).with(p12, "password").and_return(pkcs12)
         | 
| 267 | 
            +
                      end
         | 
| 268 | 
            +
             | 
| 269 | 
            +
                      it "uses the provided P12 certificate " do
         | 
| 270 | 
            +
                        subject.cert.should == cert
         | 
| 271 | 
            +
                        subject.key.should == key
         | 
| 272 | 
            +
                      end
         | 
| 273 | 
            +
             | 
| 274 | 
            +
                      it "will verify the certificate" do
         | 
| 275 | 
            +
                        subject.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
         | 
| 276 | 
            +
                      end
         | 
| 277 | 
            +
                    end
         | 
| 278 | 
            +
             | 
| 279 | 
            +
                    context "when scheme is not https" do
         | 
| 280 | 
            +
                      let(:uri) { URI 'http://google.com' }
         | 
| 281 | 
            +
                      let(:http) { Net::HTTP.new(uri) }
         | 
| 282 | 
            +
             | 
| 283 | 
            +
                      before do
         | 
| 284 | 
            +
                        Net::HTTP.stub(:new => http)
         | 
| 285 | 
            +
                        OpenSSL::PKCS12.new.should_not_receive(:new).with(p12, "password")
         | 
| 286 | 
            +
                        http.should_not_receive(:cert=)
         | 
| 287 | 
            +
                        http.should_not_receive(:key=)
         | 
| 288 | 
            +
                      end
         | 
| 289 | 
            +
             | 
| 290 | 
            +
                      it "has no PKCS12 certificate " do
         | 
| 291 | 
            +
                        subject.cert.should be_nil
         | 
| 292 | 
            +
                        subject.key.should be_nil
         | 
| 293 | 
            +
                      end
         | 
| 294 | 
            +
                    end
         | 
| 295 | 
            +
                  end
         | 
| 254 296 | 
             
                end
         | 
| 255 297 | 
             
              end
         | 
| 256 298 | 
             
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe HTTParty::Error do
         | 
| 4 | 
            +
              subject { described_class }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              its(:ancestors) { should include(StandardError) }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe HTTParty::UnsupportedFormat do
         | 
| 9 | 
            +
                its(:ancestors) { should include(HTTParty::Error) }
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              describe HTTParty::UnsupportedURIScheme do
         | 
| 13 | 
            +
                its(:ancestors) { should include(HTTParty::Error) }
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              describe HTTParty::ResponseError do
         | 
| 17 | 
            +
                its(:ancestors) { should include(HTTParty::Error) }
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              describe HTTParty::RedirectionTooDeep do
         | 
| 21 | 
            +
                its(:ancestors) { should include(HTTParty::ResponseError) }
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -112,4 +112,41 @@ describe Net::HTTPHeader::DigestAuthenticator do | |
| 112 112 | 
             
                  authorization_header.should include(%Q(response="#{request_digest}"))
         | 
| 113 113 | 
             
                end
         | 
| 114 114 | 
             
              end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              context "with multiple authenticate headers" do
         | 
| 117 | 
            +
                before do
         | 
| 118 | 
            +
                  @digest = setup_digest({
         | 
| 119 | 
            +
                    'www-authenticate' => 'NTLM, Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"',
         | 
| 120 | 
            +
                  })
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                it "should set prefix" do
         | 
| 124 | 
            +
                  authorization_header.should =~ /^Digest /
         | 
| 125 | 
            +
                end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                it "should set username" do
         | 
| 128 | 
            +
                  authorization_header.should include(%Q(username="Mufasa"))
         | 
| 129 | 
            +
                end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                it "should set digest-uri" do
         | 
| 132 | 
            +
                  authorization_header.should include(%Q(uri="/dir/index.html"))
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                it "should set qop" do
         | 
| 136 | 
            +
                  authorization_header.should include(%Q(qop="auth"))
         | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                it "should set cnonce" do
         | 
| 140 | 
            +
                  authorization_header.should include(%Q(cnonce="md5(deadbeef)"))
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                it "should set nonce-count" do
         | 
| 144 | 
            +
                  authorization_header.should include(%Q(nc=00000001))
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                it "should set response" do
         | 
| 148 | 
            +
                  request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
         | 
| 149 | 
            +
                  authorization_header.should include(%Q(response="#{request_digest}"))
         | 
| 150 | 
            +
                end
         | 
| 151 | 
            +
              end
         | 
| 115 152 | 
             
            end
         | 
| @@ -156,5 +156,10 @@ describe HTTParty::Parser do | |
| 156 156 | 
             
                it "parses plain text by simply returning the body" do
         | 
| 157 157 | 
             
                  subject.send(:plain).should == 'body'
         | 
| 158 158 | 
             
                end
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                it "parses csv with CSV" do
         | 
| 161 | 
            +
                  CSV.should_receive(:parse).with('body')
         | 
| 162 | 
            +
                  subject.send(:csv)
         | 
| 163 | 
            +
                end
         | 
| 159 164 | 
             
              end
         | 
| 160 165 | 
             
            end
         | 
| @@ -21,8 +21,8 @@ describe HTTParty::Request do | |
| 21 21 | 
             
                  end
         | 
| 22 22 |  | 
| 23 23 | 
             
                  it "URI encodes array values" do
         | 
| 24 | 
            -
                    query_string = normalizer[{:people => ["Bob Marley", "Tim & Jon"]}]
         | 
| 25 | 
            -
                    query_string.should == "people=Bob%20Marley&people=Tim%20%26%20Jon"
         | 
| 24 | 
            +
                    query_string = normalizer[{:people => ["Otis Redding", "Bob Marley", "Tim & Jon"], :page => 1, :xyzzy => 3}]
         | 
| 25 | 
            +
                    query_string.should == "page=1&people=Otis%20Redding&people=Bob%20Marley&people=Tim%20%26%20Jon&xyzzy=3"
         | 
| 26 26 | 
             
                  end
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| @@ -133,6 +133,12 @@ describe HTTParty::Request do | |
| 133 133 | 
             
                    URI.unescape(@request.uri.query).should == ""
         | 
| 134 134 | 
             
                  end
         | 
| 135 135 |  | 
| 136 | 
            +
                  it "does not append an ampersand when queries are embedded in paths" do
         | 
| 137 | 
            +
                    @request.path = "/path?a=1"
         | 
| 138 | 
            +
                    @request.options[:query] = {}
         | 
| 139 | 
            +
                    @request.uri.query.should == "a=1"
         | 
| 140 | 
            +
                  end
         | 
| 141 | 
            +
             | 
| 136 142 | 
             
                  it "does not duplicate query string parameters when uri is called twice" do
         | 
| 137 143 | 
             
                    @request.options[:query] = {:foo => :bar}
         | 
| 138 144 | 
             
                    @request.uri
         | 
| @@ -196,6 +202,24 @@ describe HTTParty::Request do | |
| 196 202 | 
             
                  end
         | 
| 197 203 | 
             
                end
         | 
| 198 204 |  | 
| 205 | 
            +
                it 'should handle text/csv' do
         | 
| 206 | 
            +
                  ["text/csv", "text/csv; charset=iso8859-1"].each do |ct|
         | 
| 207 | 
            +
                    @request.send(:format_from_mimetype, ct).should == :csv
         | 
| 208 | 
            +
                  end
         | 
| 209 | 
            +
                end
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                it 'should handle application/csv' do
         | 
| 212 | 
            +
                  ["application/csv", "application/csv; charset=iso8859-1"].each do |ct|
         | 
| 213 | 
            +
                    @request.send(:format_from_mimetype, ct).should == :csv
         | 
| 214 | 
            +
                  end
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                it 'should handle text/comma-separated-values' do
         | 
| 218 | 
            +
                  ["text/comma-separated-values", "text/comma-separated-values; charset=iso8859-1"].each do |ct|
         | 
| 219 | 
            +
                    @request.send(:format_from_mimetype, ct).should == :csv
         | 
| 220 | 
            +
                  end
         | 
| 221 | 
            +
                end
         | 
| 222 | 
            +
             | 
| 199 223 | 
             
                it 'should handle text/javascript' do
         | 
| 200 224 | 
             
                  ["text/javascript", "text/javascript; charset=iso8859-1"].each do |ct|
         | 
| 201 225 | 
             
                    @request.send(:format_from_mimetype, ct).should == :plain
         | 
| @@ -225,6 +249,12 @@ describe HTTParty::Request do | |
| 225 249 | 
             
                  @request.send(:parse_response, xml).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
         | 
| 226 250 | 
             
                end
         | 
| 227 251 |  | 
| 252 | 
            +
                it 'should handle csv automatically' do
         | 
| 253 | 
            +
                  csv=[%q["id","Name"],%q["1234","Foo Bar!"]].join("\n")
         | 
| 254 | 
            +
                  @request.options[:format] = :csv
         | 
| 255 | 
            +
                  @request.send(:parse_response, csv).should == [["id","Name"],["1234","Foo Bar!"]]
         | 
| 256 | 
            +
                end
         | 
| 257 | 
            +
             | 
| 228 258 | 
             
                it 'should handle json automatically' do
         | 
| 229 259 | 
             
                  json = %q[{"books": {"book": {"name": "Foo Bar!", "id": "1234"}}}]
         | 
| 230 260 | 
             
                  @request.options[:format] = :json
         | 
    
        data/spec/httparty_spec.rb
    CHANGED
    
    | @@ -38,6 +38,18 @@ describe HTTParty do | |
| 38 38 | 
             
                end
         | 
| 39 39 | 
             
              end
         | 
| 40 40 |  | 
| 41 | 
            +
              describe "pkcs12" do
         | 
| 42 | 
            +
                it 'should set the p12 content' do
         | 
| 43 | 
            +
                  @klass.pkcs12 'P12-CONTENT', 'PASSWORD'
         | 
| 44 | 
            +
                  @klass.default_options[:p12].should == 'P12-CONTENT'
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                it 'should set the password' do
         | 
| 48 | 
            +
                  @klass.pkcs12 'P12-CONTENT', 'PASSWORD'
         | 
| 49 | 
            +
                  @klass.default_options[:p12_password].should == 'PASSWORD'
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 41 53 | 
             
              describe 'ssl_version' do
         | 
| 42 54 | 
             
                it 'should set the ssl_version content' do
         | 
| 43 55 | 
             
                  @klass.ssl_version :SSLv3
         | 
| @@ -148,12 +160,18 @@ describe HTTParty do | |
| 148 160 | 
             
                  @klass.get('')
         | 
| 149 161 | 
             
                end
         | 
| 150 162 |  | 
| 151 | 
            -
                it " | 
| 152 | 
            -
                  expect_headers(:baz => 'spax')
         | 
| 163 | 
            +
                it "merges class headers with request headers" do
         | 
| 164 | 
            +
                  expect_headers(:baz => 'spax', :foo => 'bar')
         | 
| 153 165 | 
             
                  @klass.headers(:foo => 'bar')
         | 
| 154 166 | 
             
                  @klass.get('', :headers => {:baz => 'spax'})
         | 
| 155 167 | 
             
                end
         | 
| 156 168 |  | 
| 169 | 
            +
                it 'overrides class headers with request headers' do
         | 
| 170 | 
            +
                  expect_headers(:baz => 'spax', :foo => 'baz')
         | 
| 171 | 
            +
                  @klass.headers(:foo => 'bar')
         | 
| 172 | 
            +
                  @klass.get('', :headers => {:baz => 'spax', :foo => 'baz'})
         | 
| 173 | 
            +
                end
         | 
| 174 | 
            +
             | 
| 157 175 | 
             
                context "with cookies" do
         | 
| 158 176 | 
             
                  it 'utilizes the class-level cookies' do
         | 
| 159 177 | 
             
                    expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
         | 
| @@ -379,6 +397,11 @@ describe HTTParty do | |
| 379 397 | 
             
                  @klass.default_options[:format].should == :xml
         | 
| 380 398 | 
             
                end
         | 
| 381 399 |  | 
| 400 | 
            +
                it "should allow csv" do
         | 
| 401 | 
            +
                  @klass.format :csv
         | 
| 402 | 
            +
                  @klass.default_options[:format].should == :csv
         | 
| 403 | 
            +
                end
         | 
| 404 | 
            +
             | 
| 382 405 | 
             
                it "should allow json" do
         | 
| 383 406 | 
             
                  @klass.format :json
         | 
| 384 407 | 
             
                  @klass.default_options[:format].should == :json
         | 
| @@ -398,7 +421,7 @@ describe HTTParty do | |
| 398 421 | 
             
                it 'should only print each format once with an exception' do
         | 
| 399 422 | 
             
                  lambda do
         | 
| 400 423 | 
             
                    @klass.format :foobar
         | 
| 401 | 
            -
                  end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: html, json, plain, xml")
         | 
| 424 | 
            +
                  end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: csv, html, json, plain, xml")
         | 
| 402 425 | 
             
                end
         | 
| 403 426 |  | 
| 404 427 | 
             
                it 'sets the default parser' do
         | 
| @@ -691,6 +714,14 @@ describe HTTParty do | |
| 691 714 | 
             
                  }
         | 
| 692 715 | 
             
                end
         | 
| 693 716 |  | 
| 717 | 
            +
                it "should be able parse response type csv automatically" do
         | 
| 718 | 
            +
                  stub_http_response_with('twitter.csv')
         | 
| 719 | 
            +
                  profile = HTTParty.get('http://twitter.com/statuses/profile.csv')
         | 
| 720 | 
            +
                  profile.size.should == 2
         | 
| 721 | 
            +
                  profile[0].should == ["name","url","id","description","protected","screen_name","followers_count","profile_image_url","location"]
         | 
| 722 | 
            +
                  profile[1].should == ["Magic 8 Bot",nil,"17656026","ask me a question","false","magic8bot","90","http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg",nil]
         | 
| 723 | 
            +
                end
         | 
| 724 | 
            +
             | 
| 694 725 | 
             
                it "should not get undefined method add_node for nil class for the following xml" do
         | 
| 695 726 | 
             
                  stub_http_response_with('undefined_method_add_node_for_nil.xml')
         | 
| 696 727 | 
             
                  result = HTTParty.get('http://foobar.com')
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: httparty
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.13.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - John Nunemaker
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2014-02-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: json
         | 
| @@ -112,11 +112,13 @@ files: | |
| 112 112 | 
             
            - spec/fixtures/ssl/generated/server.crt
         | 
| 113 113 | 
             
            - spec/fixtures/ssl/generated/server.key
         | 
| 114 114 | 
             
            - spec/fixtures/ssl/openssl-exts.cnf
         | 
| 115 | 
            +
            - spec/fixtures/twitter.csv
         | 
| 115 116 | 
             
            - spec/fixtures/twitter.json
         | 
| 116 117 | 
             
            - spec/fixtures/twitter.xml
         | 
| 117 118 | 
             
            - spec/fixtures/undefined_method_add_node_for_nil.xml
         | 
| 118 119 | 
             
            - spec/httparty/connection_adapter_spec.rb
         | 
| 119 120 | 
             
            - spec/httparty/cookie_hash_spec.rb
         | 
| 121 | 
            +
            - spec/httparty/exception_spec.rb
         | 
| 120 122 | 
             
            - spec/httparty/logger/apache_logger_spec.rb
         | 
| 121 123 | 
             
            - spec/httparty/logger/curl_logger_spec.rb
         | 
| 122 124 | 
             
            - spec/httparty/logger/logger_spec.rb
         | 
| @@ -182,11 +184,13 @@ test_files: | |
| 182 184 | 
             
            - spec/fixtures/ssl/generated/server.crt
         | 
| 183 185 | 
             
            - spec/fixtures/ssl/generated/server.key
         | 
| 184 186 | 
             
            - spec/fixtures/ssl/openssl-exts.cnf
         | 
| 187 | 
            +
            - spec/fixtures/twitter.csv
         | 
| 185 188 | 
             
            - spec/fixtures/twitter.json
         | 
| 186 189 | 
             
            - spec/fixtures/twitter.xml
         | 
| 187 190 | 
             
            - spec/fixtures/undefined_method_add_node_for_nil.xml
         | 
| 188 191 | 
             
            - spec/httparty/connection_adapter_spec.rb
         | 
| 189 192 | 
             
            - spec/httparty/cookie_hash_spec.rb
         | 
| 193 | 
            +
            - spec/httparty/exception_spec.rb
         | 
| 190 194 | 
             
            - spec/httparty/logger/apache_logger_spec.rb
         | 
| 191 195 | 
             
            - spec/httparty/logger/curl_logger_spec.rb
         | 
| 192 196 | 
             
            - spec/httparty/logger/logger_spec.rb
         |