api_hammer 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa33b65d40e0ebef568c1a0da19a598da4a8e21b
4
- data.tar.gz: 37aed9c6adcbc5aeaedd3776f503047e57095caa
3
+ metadata.gz: d812135b67bb320c645f0adaa2a50384f7c4e81b
4
+ data.tar.gz: 3f8c644149a7ad7878d50af7dd1fb2fbd4ce1166
5
5
  SHA512:
6
- metadata.gz: 6d34d68f09541878f3ab910a975bb43633d00b490e10ea2febb4cae42af8a1c27489d656eb8e0aa77e7191fecccb15d24e4afb466e688faaf92f5e9443fae59f
7
- data.tar.gz: 7e2cb70f0271b4f4bebd43c7e4e6f8c8ed73ca321b07fc4b6361279b0136d7b3df6dab06505443f0404b66b720101bb78b477428633c8de0d3cbde3218ae2080
6
+ metadata.gz: f06fc026f7cc0383eed1ac89974dab0e1d3d9d6067a0d4c95d09c8397f7cbfd825e201c5a4720fc097d3099091d232a7e80e29fce20d2c45ca07eb6fdfa23fc1
7
+ data.tar.gz: 3400cc586418fc47faffd6462f78626229d84361f703c9675f6af44978633629aa3104665f1618f11fd33f7480d5a22cc71a2035e463e4e3716946463e9f433c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.17.0
2
+ - fix ApiHammer::ShowTextExceptions middleware to not rescue certain exceptions
3
+ - don't insert or rely on Rack::Accept middleware for sinatra; use Rack::Accept more directly
4
+ - improve hc User-Agent
5
+
1
6
  # v0.16.0
2
7
  - fix dependency on json pure parser, which moved from the json gem to json_pure gem
3
8
 
data/Gemfile CHANGED
@@ -5,3 +5,6 @@ gemspec
5
5
 
6
6
  gem 'byebug'
7
7
  gem 'wwtd'
8
+ if RUBY_VERSION == '2.0.0'
9
+ gem 'nokogiri', '~> 1.6.8'
10
+ end
data/bin/hc CHANGED
@@ -123,7 +123,7 @@ if body && !headers['Content-Type'.downcase]
123
123
  end
124
124
 
125
125
  unless headers.keys.any? { |key| key.downcase == 'user-agent' }
126
- headers['User-Agent'] = "ApiHammer #{ApiHammer::VERSION} hc"
126
+ headers['User-Agent'] = "ApiHammer-hc/#{ApiHammer::VERSION} (#{RUBY_ENGINE} #{RUBY_VERSION}; #{RUBY_PLATFORM})"
127
127
  end
128
128
 
129
129
  # OH LOOK IT'S FINALLY ACTUALLY CONNECTING TO SOMETHING
@@ -7,3 +7,7 @@ gem 'wwtd'
7
7
 
8
8
  gem 'rack', '~> 1.0'
9
9
  gem 'actionpack', '~> 4.0'
10
+
11
+ if RUBY_VERSION == '2.0.0'
12
+ gem 'nokogiri', '~> 1.6.8'
13
+ end
@@ -7,3 +7,7 @@ gem 'wwtd'
7
7
 
8
8
  gem 'rack', '~> 2.0'
9
9
  gem 'actionpack', '~> 5.0'
10
+
11
+ if RUBY_VERSION == '2.0.0'
12
+ gem 'nokogiri', '~> 1.6.8'
13
+ end
@@ -9,6 +9,19 @@ module ApiHammer
9
9
  # those middlewares have a #prefers_plain_text? method which makes them behave like this, but
10
10
  # it's simpler and more reliable to roll our own than monkey-patch those)
11
11
  class ShowTextExceptions
12
+ # this module blatantly stolen from
13
+ # https://github.com/rspec/rspec-support/blob/v3.5.0/lib/rspec/support.rb#L121-L130
14
+ # under MIT license https://github.com/rspec/rspec-support/blob/v3.5.0/LICENSE.md
15
+ module AllExceptionsExceptOnesWeMustNotRescue
16
+ # These exceptions are dangerous to rescue as rescuing them
17
+ # would interfere with things we should not interfere with.
18
+ AVOID_RESCUING = [NoMemoryError, SignalException, Interrupt, SystemExit]
19
+
20
+ def self.===(exception)
21
+ AVOID_RESCUING.none? { |ar| ar === exception }
22
+ end
23
+ end
24
+
12
25
  def initialize(app, options)
13
26
  @app=app
14
27
  @options = options
@@ -16,7 +29,7 @@ module ApiHammer
16
29
  def call(env)
17
30
  begin
18
31
  @app.call(env)
19
- rescue Exception => e
32
+ rescue AllExceptionsExceptOnesWeMustNotRescue => e
20
33
  full_error_message = (["#{e.class}: #{e.message}"] + e.backtrace.map{|l| " #{l}" }).join("\n")
21
34
  if @options[:logger]
22
35
  @options[:logger].error(full_error_message)
@@ -1,4 +1,9 @@
1
1
  require 'api_hammer/sinatra/halt'
2
+ begin
3
+ require 'rack/accept'
4
+ rescue LoadError => e
5
+ raise e.class, e.message + "\nPlease `gem install rack_accept` or add rack_accept to your Gemfile", e.backtrace
6
+ end
2
7
 
3
8
  module ApiHammer
4
9
  module Sinatra
@@ -27,10 +32,6 @@ module ApiHammer
27
32
  use middleware, *args, &block
28
33
  use Rack::Lint if development? || test?
29
34
  end
30
-
31
- # ApiHammer::Sinatra's methods use Rack::Accept so we will go ahead and put this middleware
32
- # in the stack
33
- klass.use_with_lint Rack::Accept
34
35
  end
35
36
  end
36
37
 
@@ -60,10 +61,11 @@ module ApiHammer
60
61
  # returns the first supported media type.
61
62
  def response_media_type(options={})
62
63
  options = {:halt_if_unacceptable => false}.merge(options)
64
+ env = options[:env] || (respond_to?(:env) ? self.env : raise(ArgumentError, "must pass env"))
63
65
  accept = env['HTTP_ACCEPT']
64
66
  if accept =~ /\S/
65
67
  begin
66
- best_media_type = env['rack-accept.request'].best_media_type(supported_media_types)
68
+ best_media_type = Rack::Accept::Request.new(env).best_media_type(supported_media_types)
67
69
  rescue RuntimeError => e
68
70
  # TODO: this is a crappy way to recognize this exception
69
71
  raise unless e.message =~ /Invalid header value/
@@ -83,8 +85,10 @@ module ApiHammer
83
85
  supported_media_types.first
84
86
  end
85
87
  end
86
- else
88
+ elsif supported_media_types && supported_media_types.any?
87
89
  supported_media_types.first
90
+ else
91
+ raise "No media types are defined. Please set supported_media_types."
88
92
  end
89
93
  end
90
94
 
@@ -1,3 +1,3 @@
1
1
  module ApiHammer
2
- VERSION = "0.16.0"
2
+ VERSION = "0.17.0"
3
3
  end
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.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -305,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  version: '0'
306
306
  requirements: []
307
307
  rubyforge_project:
308
- rubygems_version: 2.5.1
308
+ rubygems_version: 2.6.11
309
309
  signing_key:
310
310
  specification_version: 4
311
311
  summary: an API tool