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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b5e34c9b253a422bf582b6181fa3f3965c18b66
4
- data.tar.gz: 416799541c1b566969c8416db53624348d38e699
3
+ metadata.gz: a9cc281675b62d8d4408ab9b0f2ef06ab9a5a6c7
4
+ data.tar.gz: 77714ae80af1572e00f5270f8ba054d59ceb2c01
5
5
  SHA512:
6
- metadata.gz: ec93a5d969d1db7b9205e25e97c474b450a6e3e7c8750daa9908e110eab3867a8e32ef4dc00d863c9b2648f56a1f47fe07d1d5ccddabc92a7ed4de0033d5f4e2
7
- data.tar.gz: 14ee3d556702b802f627945ca8127f909cc6e6c65e1a6262a39d3b6c68650eb6dcb8d252770e4c3409c71638f9f3ce210471265679b80e2226b47836f6fbd2cb
6
+ metadata.gz: 19589190d21a67f8231bd37cbbad3dc700dfa5abcfdf7c7a620cdd8b3a0f7c611f6430f5e598652d1a50fd86edfdf6064c8216af9377cba7785f0779fe9a7ec9
7
+ data.tar.gz: 9b4673a6985a061c707ec20f9984dce3966040c0b17c80ac96610ac27dfb3f24184b48230fc21d39ba9e8fb236bc370c423d90c7f0b89b6d7c188bd5972b57c5
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea/
11
+ *.iml
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
- file_path = get_template_path(env)
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 file_path
19
+ return @app.call(env) unless template_path
16
20
 
17
- response = ERB.new(::File.open(file_path, &:read), nil, '<>').result(binding)
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
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rack-apimock"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.3"
8
8
  spec.authors = ["hiro-su"]
9
9
  spec.email = ["h.sugipon@gmail.com"]
10
10
 
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.2
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-15 00:00:00.000000000 Z
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler