api_hammer 0.18.0 → 0.18.1

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: 389df34af6fc825bf80bd8460ec43ca7ea626d52
4
- data.tar.gz: ad21026ef421554be76e50158c4fe438c9ac2f61
3
+ metadata.gz: e91b96d24872a1d8bed529e435ee220fedc2f90e
4
+ data.tar.gz: 79efc1dc82362fa52906e83314b1ce10e0a2872f
5
5
  SHA512:
6
- metadata.gz: fbc5733ba3f575fce86e74b469c3996884c5a6a8f5a622d47008b4635d5f443fe61d91d24697b964138995337306d8e20777e5d834cd51f554bd41542d06ebfe
7
- data.tar.gz: f29386f32c2a6d89bc78661ea05c494b25576c59a4c8e7448af6994e44287074c068b662fb2e3bf73dabd15ae2745d871e42959690d1853c02304f13b7dc2e6b
6
+ metadata.gz: 465349874c9e57aa860d70de8bee3386b4497bbc06adae9242e6b9ee16afd629f424a76d5b5693ac11a484ee82993ec7b619cf85cd4550be8562c1e9ada0ec64
7
+ data.tar.gz: ca74a38d500888996b05a558815f9d0b59217dd46dc12195467c911db9bc869e1ff9d514036a302264694d4465095cda8faabae368a9c37d9551dacbf0d79031
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.18.1
2
+ - improve supported media types for sinatra
3
+ - report to Rollbar on 4xx if Rollbar available
4
+
1
5
  # v0.18.0
2
6
  - add option to hc for basic auth
3
7
  - add option to hc to make it consider the body as text
@@ -2,7 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'byebug'
6
5
  gem 'wwtd'
7
6
 
8
7
  gem 'rack', '~> 1.0'
@@ -10,4 +9,5 @@ gem 'actionpack', '~> 4.0'
10
9
 
11
10
  if RUBY_VERSION == '2.0.0'
12
11
  gem 'nokogiri', '~> 1.6.8'
12
+ gem 'public_suffix', '~> 2.0'
13
13
  end
@@ -2,7 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'byebug'
6
5
  gem 'wwtd'
7
6
 
8
7
  gem 'rack', '~> 2.0'
@@ -31,6 +31,9 @@ module ApiHammer
31
31
  end
32
32
  end
33
33
  body['error_message'] = error_message if error_message
34
+ if Object.const_defined?(:Rollbar) and status != 404
35
+ Rollbar.debug "Service halted with status #{status}", status: status, body: body, halt_options: halt_options
36
+ end
34
37
  halt(status, body, halt_options)
35
38
  end
36
39
 
@@ -3,7 +3,7 @@ require 'api_hammer/halt_methods'
3
3
  # the contents of this file are to let you halt a controller in its processing without having to have a
4
4
  # return in the actual action. this lets helper methods which do things like parameter validation halt.
5
5
  #
6
- # it is desgined to function similarly to Sinatra's handling of throw(:halt), but is based around exceptions
6
+ # it is designed to function similarly to Sinatra's handling of throw(:halt), but is based around exceptions
7
7
  # because rails doesn't catch anything, just rescues.
8
8
 
9
9
  module ApiHammer::Rails
@@ -46,8 +46,11 @@ module ApiHammer
46
46
 
47
47
  include ApiHammer::Sinatra::Halt
48
48
 
49
+ # supported_media_types may be defined for the instance (applying to one request) or on the class
50
+ # (applying to the whole sinatra app)
51
+ attr_writer :supported_media_types
49
52
  def supported_media_types
50
- self.class.supported_media_types
53
+ instance_variable_defined?(:@supported_media_types) ? @supported_media_types : self.class.supported_media_types
51
54
  end
52
55
 
53
56
  # finds the best match (highest q) for those supported_media_types indicated as acceptable by the Accept header.
@@ -62,6 +65,7 @@ module ApiHammer
62
65
  def response_media_type(options={})
63
66
  options = {:halt_if_unacceptable => false}.merge(options)
64
67
  env = options[:env] || (respond_to?(:env) ? self.env : raise(ArgumentError, "must pass env"))
68
+ supported_media_types = options[:supported_media_types] || self.supported_media_types
65
69
  accept = env['HTTP_ACCEPT']
66
70
  if accept =~ /\S/
67
71
  begin
@@ -92,8 +96,8 @@ module ApiHammer
92
96
  end
93
97
  end
94
98
 
95
- def check_accept
96
- response_media_type(:halt_if_unacceptable => true)
99
+ def check_accept(options = {})
100
+ response_media_type(options.merge(:halt_if_unacceptable => true))
97
101
  end
98
102
 
99
103
  # returns a rack response with the given object encoded in the appropriate format for the requests.
@@ -107,6 +111,12 @@ module ApiHammer
107
111
  body = case response_media_type
108
112
  when 'application/json'
109
113
  JSON.pretty_generate(body_object)
114
+ when 'application/x-www-form-urlencoded'
115
+ URI.encode_www_form(body_object)
116
+ when 'application/xml'
117
+ body_object.to_s
118
+ when 'text/plain'
119
+ body_object
110
120
  else
111
121
  # :nocov:
112
122
  raise NotImplementedError, "unsupported response media type #{response_media_type}"
@@ -1,3 +1,3 @@
1
1
  module ApiHammer
2
- VERSION = "0.18.0"
2
+ VERSION = "0.18.1"
3
3
  end
data/test/helper.rb CHANGED
@@ -4,7 +4,6 @@ require 'bundler'
4
4
  Bundler.setup
5
5
 
6
6
  require 'simplecov'
7
- require 'byebug'
8
7
 
9
8
  # NO EXPECTATIONS
10
9
  ENV["MT_NO_EXPECTATIONS"] = ''
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.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack