api_hammer 0.17.0 → 0.18.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/bin/hc +14 -0
- data/lib/api_hammer/faraday/outputter.rb +1 -1
- data/lib/api_hammer/faraday/request_logger.rb +5 -5
- data/lib/api_hammer/rails/halt.rb +1 -1
- data/lib/api_hammer/sinatra.rb +1 -1
- data/lib/api_hammer/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 389df34af6fc825bf80bd8460ec43ca7ea626d52
         | 
| 4 | 
            +
              data.tar.gz: ad21026ef421554be76e50158c4fe438c9ac2f61
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fbc5733ba3f575fce86e74b469c3996884c5a6a8f5a622d47008b4635d5f443fe61d91d24697b964138995337306d8e20777e5d834cd51f554bd41542d06ebfe
         | 
| 7 | 
            +
              data.tar.gz: f29386f32c2a6d89bc78661ea05c494b25576c59a4c8e7448af6994e44287074c068b662fb2e3bf73dabd15ae2745d871e42959690d1853c02304f13b7dc2e6b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,9 @@ | |
| 1 | 
            +
            # v0.18.0
         | 
| 2 | 
            +
            - add option to hc for basic auth
         | 
| 3 | 
            +
            - add option to hc to make it consider the body as text
         | 
| 4 | 
            +
            - faraday logger compatibility with old faraday 0.8
         | 
| 5 | 
            +
            - fix ruby warnings
         | 
| 6 | 
            +
             | 
| 1 7 | 
             
            # v0.17.0
         | 
| 2 8 | 
             
            - fix ApiHammer::ShowTextExceptions middleware to not rescue certain exceptions
         | 
| 3 9 | 
             
            - don't insert or rely on Rack::Accept middleware for sinatra; use Rack::Accept more directly
         | 
    
        data/bin/hc
    CHANGED
    
    | @@ -23,9 +23,11 @@ $options = { | |
| 23 23 | 
             
              :pretty => nil,
         | 
| 24 24 | 
             
              :no_ssl_verify => false,
         | 
| 25 25 | 
             
              :headers => {},
         | 
| 26 | 
            +
              :text => nil,
         | 
| 26 27 | 
             
            }
         | 
| 27 28 |  | 
| 28 29 | 
             
            $oauth = {}
         | 
| 30 | 
            +
            $basicauth = {}
         | 
| 29 31 |  | 
| 30 32 | 
             
            opt_parser = OptionParser.new do |opts|
         | 
| 31 33 | 
             
              opts.banner = "Usage: #{$0} [options] <verb> <url> [body]"
         | 
| @@ -33,6 +35,9 @@ opt_parser = OptionParser.new do |opts| | |
| 33 35 | 
             
              opts.on("-v", "--[no-]verbose", "Run verbosely - output is like curl -v (this is the default)") do |v|
         | 
| 34 36 | 
             
                $options[:verbose] = v
         | 
| 35 37 | 
             
              end
         | 
| 38 | 
            +
              opts.on("--[no-]text", "consider the response body to be text (default relies on Content-Type)") do |v|
         | 
| 39 | 
            +
                $options[:text] = v
         | 
| 40 | 
            +
              end
         | 
| 36 41 | 
             
              opts.on("-q", "Run quietly - only outputs the response body (same as --no-verbose)") do |v|
         | 
| 37 42 | 
             
                $options[:verbose] = !v
         | 
| 38 43 | 
             
              end
         | 
| @@ -66,6 +71,12 @@ opt_parser = OptionParser.new do |opts| | |
| 66 71 | 
             
              opts.on("--oauth-signature-method SIGNATURE_METHOD", "OAuth 1.0 signature method - defaults to HMAC-SHA1") do |signature_method|
         | 
| 67 72 | 
             
                $oauth[:signature_method] = signature_method
         | 
| 68 73 | 
             
              end
         | 
| 74 | 
            +
              opts.on("--basic-user USER", "basic auth user") do |user|
         | 
| 75 | 
            +
                $basicauth[:user] = user
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
              opts.on("--basic-password PASSWORD", "basic auth password") do |password|
         | 
| 78 | 
            +
                $basicauth[:password] = password
         | 
| 79 | 
            +
              end
         | 
| 69 80 |  | 
| 70 81 | 
             
              opts.on("--no-ssl-verify", "Disables SSL verification - use cautiously!") do
         | 
| 71 82 | 
             
                $options[:no_ssl_verify] = true
         | 
| @@ -95,6 +106,9 @@ connection = Faraday.new(faraday_options) do |builder| | |
| 95 106 | 
             
                OAuthenticator::FaradaySigner
         | 
| 96 107 | 
             
                builder.use OAuthenticator::FaradaySigner, $oauth
         | 
| 97 108 | 
             
              end
         | 
| 109 | 
            +
              if $basicauth.any?
         | 
| 110 | 
            +
                builder.basic_auth($basicauth[:user], $basicauth[:password])
         | 
| 111 | 
            +
              end
         | 
| 98 112 | 
             
              builder.use($options[:verbose] ? ApiHammer::FaradayCurlVOutputter : ApiHammer::FaradayOutputter, $options)
         | 
| 99 113 | 
             
              builder.adapter Faraday.default_adapter
         | 
| 100 114 | 
             
            end
         | 
| @@ -129,7 +129,7 @@ module ApiHammer | |
| 129 129 | 
             
                def alter_body_by_content_type(body, content_type)
         | 
| 130 130 | 
             
                  return body unless body.is_a?(String)
         | 
| 131 131 | 
             
                  content_type_attrs = ApiHammer::ContentTypeAttrs.new(content_type)
         | 
| 132 | 
            -
                  if content_type_attrs.text?
         | 
| 132 | 
            +
                  if @options[:text].nil? ? content_type_attrs.text? : @options[:text]
         | 
| 133 133 | 
             
                    if pretty?
         | 
| 134 134 | 
             
                      case content_type_attrs.media_type
         | 
| 135 135 | 
             
                      when 'application/json'
         | 
| @@ -37,12 +37,12 @@ module ApiHammer | |
| 37 37 |  | 
| 38 38 | 
             
                    @app.call(request_env).on_complete do |response_env|
         | 
| 39 39 | 
             
                      now = Time.now
         | 
| 40 | 
            -
                      status = response_env | 
| 40 | 
            +
                      status = response_env[:status]
         | 
| 41 41 |  | 
| 42 42 | 
             
                      if log_bodies(status)
         | 
| 43 43 | 
             
                        bodies = [
         | 
| 44 | 
            -
                          ['request', request_body, request_env | 
| 45 | 
            -
                          ['response', response_env | 
| 44 | 
            +
                          ['request', request_body, request_env[:request_headers]],
         | 
| 45 | 
            +
                          ['response', response_env[:body], response_env[:response_headers]]
         | 
| 46 46 | 
             
                        ].map do |(role, body_s, headers)|
         | 
| 47 47 | 
             
                          body = Body.new(body_s, headers['Content-Type'])
         | 
| 48 48 | 
             
                          if body.content_type_attrs.text?
         | 
| @@ -62,12 +62,12 @@ module ApiHammer | |
| 62 62 | 
             
                        'request' => {
         | 
| 63 63 | 
             
                          'method' => request_env[:method],
         | 
| 64 64 | 
             
                          'uri' => request_env[:url].normalize.to_s,
         | 
| 65 | 
            -
                          'headers' => request_env | 
| 65 | 
            +
                          'headers' => request_env[:request_headers],
         | 
| 66 66 | 
             
                          'body' => bodies['request'],
         | 
| 67 67 | 
             
                        }.reject{|k,v| v.nil? },
         | 
| 68 68 | 
             
                        'response' => {
         | 
| 69 69 | 
             
                          'status' => status.to_s,
         | 
| 70 | 
            -
                          'headers' => response_env | 
| 70 | 
            +
                          'headers' => response_env[:response_headers],
         | 
| 71 71 | 
             
                          'body' => bodies['response'],
         | 
| 72 72 | 
             
                        }.reject{|k,v| v.nil? },
         | 
| 73 73 | 
             
                        'processing' => {
         | 
| @@ -19,7 +19,7 @@ module ApiHammer::Rails | |
| 19 19 | 
             
                attr_reader :body, :render_options
         | 
| 20 20 | 
             
              end
         | 
| 21 21 |  | 
| 22 | 
            -
              unless  | 
| 22 | 
            +
              unless instance_variable_defined?(:@rails_halt_included_defined)
         | 
| 23 23 | 
             
                @rails_halt_included_defined = true
         | 
| 24 24 | 
             
                (@on_included ||= Set.new) << proc do |controller_class|
         | 
| 25 25 | 
             
                  controller_class.send(:rescue_from, ApiHammer::Rails::Halt, :with => :handle_halt)
         | 
    
        data/lib/api_hammer/sinatra.rb
    CHANGED
    
    
    
        data/lib/api_hammer/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: api_hammer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.18.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ethan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-05-30 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rack
         |