rack-apimock 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rack/apimock.rb +7 -4
- data/rack-apimock.gemspec +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: a9cc281675b62d8d4408ab9b0f2ef06ab9a5a6c7
|
4
|
+
data.tar.gz: 77714ae80af1572e00f5270f8ba054d59ceb2c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19589190d21a67f8231bd37cbbad3dc700dfa5abcfdf7c7a620cdd8b3a0f7c611f6430f5e598652d1a50fd86edfdf6064c8216af9377cba7785f0779fe9a7ec9
|
7
|
+
data.tar.gz: 9b4673a6985a061c707ec20f9984dce3966040c0b17c80ac96610ac27dfb3f24184b48230fc21d39ba9e8fb236bc370c423d90c7f0b89b6d7c188bd5972b57c5
|
data/.gitignore
CHANGED
data/lib/rack/apimock.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'erb'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module Rack
|
4
5
|
class APIMock
|
@@ -9,19 +10,21 @@ module Rack
|
|
9
10
|
|
10
11
|
def call(env)
|
11
12
|
@status, @headers = 200, {}
|
12
|
-
|
13
|
+
if env["CONTENT_TYPE"] =~ /application\/json/i
|
14
|
+
@request_body = JSON.parse(env["rack.input"].gets) rescue nil
|
15
|
+
end
|
16
|
+
template_path = get_template_path(env)
|
13
17
|
|
14
18
|
# Missing Template File
|
15
|
-
return @app.call(env) unless
|
19
|
+
return @app.call(env) unless template_path
|
16
20
|
|
17
|
-
response = ERB.new(::File.open(
|
21
|
+
response = ERB.new(::File.open(template_path, &:read), nil, '<>').result(binding)
|
18
22
|
|
19
23
|
unless env['QUERY_STRING'].empty?
|
20
24
|
query_string = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
21
25
|
|
22
26
|
case env["CONTENT_TYPE"]
|
23
27
|
when /application\/json/i
|
24
|
-
require 'json'
|
25
28
|
data = JSON.parse(response)
|
26
29
|
response = query_string.each_with_object({}) {|(key, _), new_hash|
|
27
30
|
new_hash.merge!(key => data[key])
|
data/rack-apimock.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-apimock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hiro-su
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|