rack-parse-posted-json 0.0.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 +7 -0
- data/README.md +8 -0
- data/lib/rack-parse-posted-json.rb +30 -0
- data/spec/spec_helper.rb +0 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b4b28d8ed71f92fe99ff73b33dce1d2db0ac40a
|
4
|
+
data.tar.gz: f3913b70df99d4746b312666d76ef12960e9614b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a3daf644478d1d755d9fecd4ff1c1cbeee47c7642aa5a36aa8e1897f615089563e7360811db333e1570c19e4919eb9788b87fa5cc09dd08eb53d9181cd20234
|
7
|
+
data.tar.gz: a8877e4882fcba148938c64e0dfa5d8b2e30a10e982bbc29fe44375ce6e359b380e7a486bf0e22020a79d1a15eefb0f062a9196828fd3c5142380c9b81c580da
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rack
|
2
|
+
class ParsePostedJSON
|
3
|
+
METHODS_WITH_BODY = ['POST', 'PUT']
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
begin
|
11
|
+
if METHODS_WITH_BODY.include?(env['REQUEST_METHOD'])
|
12
|
+
data = env['rack.input'].read
|
13
|
+
data.force_encoding('utf-8')
|
14
|
+
env['json'] = JSON.parse(data)
|
15
|
+
end
|
16
|
+
rescue JSON::ParserError => error
|
17
|
+
body = {message: error.message}.to_json
|
18
|
+
|
19
|
+
headers = {
|
20
|
+
'Content-Type' => 'application/json',
|
21
|
+
'Content-Length' => body.bytesize.to_s
|
22
|
+
}
|
23
|
+
|
24
|
+
return [400, headers, [body]]
|
25
|
+
end
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-parse-posted-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- https://github.com/botanicus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: Parse POSTed and PUTed JSON and make it available through env["json"].
|
28
|
+
email: james@101ideas.cz
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- lib/rack-parse-posted-json.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
homepage: https://github.com/botanicus/rack-parse-posted-json
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project: rack-parse-posted-json
|
56
|
+
rubygems_version: 2.2.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Parse POSTed and PUTed JSON.
|
60
|
+
test_files: []
|