api_hammer 0.18.0 → 0.18.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/gemfiles/Gemfile_rack_1 +1 -1
- data/gemfiles/Gemfile_rack_2 +0 -1
- data/lib/api_hammer/halt_methods.rb +3 -0
- data/lib/api_hammer/rails/halt.rb +1 -1
- data/lib/api_hammer/sinatra.rb +13 -3
- data/lib/api_hammer/version.rb +1 -1
- data/test/helper.rb +0 -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: e91b96d24872a1d8bed529e435ee220fedc2f90e
|
4
|
+
data.tar.gz: 79efc1dc82362fa52906e83314b1ce10e0a2872f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465349874c9e57aa860d70de8bee3386b4497bbc06adae9242e6b9ee16afd629f424a76d5b5693ac11a484ee82993ec7b619cf85cd4550be8562c1e9ada0ec64
|
7
|
+
data.tar.gz: ca74a38d500888996b05a558815f9d0b59217dd46dc12195467c911db9bc869e1ff9d514036a302264694d4465095cda8faabae368a9c37d9551dacbf0d79031
|
data/CHANGELOG.md
CHANGED
data/gemfiles/Gemfile_rack_1
CHANGED
data/gemfiles/Gemfile_rack_2
CHANGED
@@ -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
|
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
|
data/lib/api_hammer/sinatra.rb
CHANGED
@@ -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}"
|
data/lib/api_hammer/version.rb
CHANGED
data/test/helper.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.18.
|
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-
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|