cp-sparrow 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +2 -5
  5. data/README.md +6 -3
  6. data/Rakefile +8 -7
  7. data/lib/cp-sparrow.rb +1 -0
  8. data/lib/sparrow/configuration.rb +5 -1
  9. data/lib/sparrow/core_ext/hash.rb +22 -17
  10. data/lib/sparrow/dependencies.rb +11 -2
  11. data/lib/sparrow/logger.rb +1 -1
  12. data/lib/sparrow/railtie.rb +3 -3
  13. data/lib/sparrow/request_http_message.rb +1 -1
  14. data/lib/sparrow/response_middleware.rb +5 -5
  15. data/lib/sparrow/route_parser.rb +1 -1
  16. data/lib/sparrow/strategies/ignore.rb +2 -2
  17. data/lib/sparrow/strategies/json_format_strategies/default_json_format_strategy.rb +1 -1
  18. data/lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb +5 -4
  19. data/lib/sparrow/strategies/key_transformation/underscore_key.rb +1 -1
  20. data/lib/sparrow/strategies/transform_params.rb +5 -1
  21. data/lib/sparrow/transformable.rb +8 -8
  22. data/lib/sparrow/version.rb +1 -1
  23. data/sparrow.gemspec +5 -3
  24. data/spec/integration/apps/rack_app/app.rb +22 -5
  25. data/spec/integration/apps/rack_app/config.ru +2 -2
  26. data/spec/integration/apps/rails_app/README.rdoc +15 -248
  27. data/spec/integration/apps/rails_app/Rakefile +1 -2
  28. data/spec/integration/apps/rails_app/app/assets/images/.keep +0 -0
  29. data/spec/integration/apps/rails_app/app/assets/javascripts/application.js +4 -6
  30. data/spec/integration/apps/rails_app/app/assets/stylesheets/application.css +6 -4
  31. data/spec/integration/apps/rails_app/app/controllers/application_controller.rb +3 -1
  32. data/spec/integration/apps/rails_app/app/controllers/concerns/.keep +0 -0
  33. data/spec/integration/apps/rails_app/app/controllers/errors_controller.rb +10 -0
  34. data/spec/integration/apps/rails_app/app/controllers/welcome_controller.rb +0 -5
  35. data/spec/integration/apps/rails_app/app/mailers/.keep +0 -0
  36. data/spec/integration/apps/rails_app/app/models/.keep +0 -0
  37. data/spec/integration/apps/rails_app/app/models/concerns/.keep +0 -0
  38. data/spec/integration/apps/rails_app/app/views/layouts/application.html.erb +3 -3
  39. data/spec/integration/apps/rails_app/bin/bundle +3 -0
  40. data/spec/integration/apps/rails_app/bin/rails +4 -0
  41. data/spec/integration/apps/rails_app/bin/rake +4 -0
  42. data/spec/integration/apps/rails_app/bin/setup +29 -0
  43. data/spec/integration/apps/rails_app/config.ru +2 -2
  44. data/spec/integration/apps/rails_app/config/application.rb +6 -43
  45. data/spec/integration/apps/rails_app/config/boot.rb +4 -9
  46. data/spec/integration/apps/rails_app/config/database.yml +25 -0
  47. data/spec/integration/apps/rails_app/config/environment.rb +3 -3
  48. data/spec/integration/apps/rails_app/config/environments/development.rb +23 -13
  49. data/spec/integration/apps/rails_app/config/environments/production.rb +46 -31
  50. data/spec/integration/apps/rails_app/config/environments/test.rb +20 -10
  51. data/spec/integration/apps/rails_app/config/initializers/assets.rb +11 -0
  52. data/spec/integration/apps/rails_app/config/initializers/cookies_serializer.rb +3 -0
  53. data/spec/integration/apps/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
  54. data/spec/integration/apps/rails_app/config/initializers/inflections.rb +6 -5
  55. data/spec/integration/apps/rails_app/config/initializers/mime_types.rb +0 -1
  56. data/spec/integration/apps/rails_app/config/initializers/secret_token.rb +1 -1
  57. data/spec/integration/apps/rails_app/config/initializers/session_store.rb +1 -6
  58. data/spec/integration/apps/rails_app/config/initializers/wrap_parameters.rb +6 -2
  59. data/spec/integration/apps/rails_app/config/locales/en.yml +20 -2
  60. data/spec/integration/apps/rails_app/config/routes.rb +21 -29
  61. data/spec/integration/apps/rails_app/config/secrets.yml +22 -0
  62. data/spec/integration/apps/rails_app/lib/assets/.keep +0 -0
  63. data/spec/integration/apps/rails_app/public/404.html +54 -13
  64. data/spec/integration/apps/rails_app/public/422.html +54 -13
  65. data/spec/integration/apps/rails_app/public/500.html +53 -12
  66. data/spec/integration/rack/camel_caser_spec.rb +18 -18
  67. data/spec/integration/rack/error_spec.rb +17 -0
  68. data/spec/integration/rails/camel_caser_accept_header_spec.rb +3 -3
  69. data/spec/integration/rails/camel_caser_spec.rb +30 -19
  70. data/spec/spec_helper.rb +1 -2
  71. data/spec/support/rails_app_helper.rb +1 -1
  72. data/spec/unit/configuration_spec.rb +2 -2
  73. metadata +46 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d21e1f781a7f5f4a27d6d8c286cd46d9af31cba4
4
- data.tar.gz: 838ed5f0629f44eb18c8041c1dcaf3d5048b1630
3
+ metadata.gz: f6203b666448091c6aa36a5df6892f488a8bc96b
4
+ data.tar.gz: 9baa9565eba84c01ce3c0c742403892101c96a48
5
5
  SHA512:
6
- metadata.gz: 99f670f75b1a3dc078130af3d946738f80705f1c79e26922afbbcba0921aecaa1c38bc7edd1253fb3f0a07fbad8c9635f5d6a7e332a407b4109d8b122a59c301
7
- data.tar.gz: cd0a34026665ddfd21c075a05af4839b5f1995cc0d45d70009a205329a2862dd8eb752b243f5fa6c1937b2e973245a3130a2d2c33d25ced0bccbef71761b41df
6
+ metadata.gz: 151bd8ceaf5864f652d6479fa4bcfe84151b84fe3045b298a4208fd9edaed7a1ca1b573c758062f019824657bef7384f5d4ff5b5bf1f937f225273ae531cc834
7
+ data.tar.gz: c18506cee9974098896291c53ed2b836110411717600598ae7bde84b1b23dbce326e11c87e7a717a8e3e1292ae7fc5405c373861011b9dded0227af41748c775
data/.gitignore CHANGED
@@ -22,3 +22,4 @@ tmp
22
22
  .idea
23
23
  .project
24
24
  hoogfile.yml
25
+ .tags*
@@ -1 +1 @@
1
- 2.2
1
+ 2.3.1
@@ -1,8 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- # - 2.0.0
4
- - 2.1.0
5
- # - 2.2.0
3
+ - 2.3.1
6
4
  env:
7
- - RAILS_VERSION: 3.2.21
8
- - RAILS_VERSION: 4.0.13
5
+ - RAILS_VERSION: 4.2.6
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
1
  # Sparrow
2
2
 
3
+ [![Little Sparrow by Apofiss](http://orig07.deviantart.net/d937/f/2015/064/c/1/little_sparrow_by_apofiss-d5wpswt.jpg)](http://www.deviantart.com/art/Little-Sparrow-357282461)
4
+
3
5
  A Rack middleware for converting the params keys and JSON response keys of a Rack application.
4
6
 
5
7
  [![Build Status](https://travis-ci.org/GateprotectGmbH/sparrow.svg?branch=master)](https://travis-ci.org/GateprotectGmbH/sparrow) [![Gem Version](https://badge.fury.io/rb/cp-sparrow.svg)](http://badge.fury.io/rb/cp-sparrow)
8
+ [![Code Climate](https://codeclimate.com/github/GateprotectGmbH/sparrow/badges/gpa.svg)](https://codeclimate.com/github/GateprotectGmbH/sparrow)
6
9
 
7
10
  ## Installation
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
11
- gem 'cp-sparrow', require: 'sparrow'
14
+ gem 'cp-sparrow'
12
15
 
13
16
  And then execute:
14
17
 
@@ -58,7 +61,7 @@ Example:
58
61
 
59
62
  ### default_json_request_key_transformation_strategy
60
63
 
61
- > `String`. Default: `camelize`
64
+ > `String`. Default: `underscore`
62
65
 
63
66
  Defines how the middleware should treat incoming parameters via Request. Which means how they get tranformed, i.e. defining _underscore_ here means that incoming parameters get underscore. Possible values are _underscore_ and _camelize_
64
67
 
@@ -133,7 +136,7 @@ Example:
133
136
 
134
137
  > `Symbol`. Default: `:lower`
135
138
 
136
- Defines which strategy to use when camelizing keys. Possible options are `:lower` and `:upper`, which tells the middleware to
139
+ Defines which strategy to use when camelizing keys. Possible options are `:lower` and `:upper`, which tells the middleware to
137
140
  start camelized keys with an uppercased character or with a lowercased character.
138
141
 
139
142
  Example:
data/Rakefile CHANGED
@@ -4,8 +4,7 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  RAILS_VERSIONS = [
7
- "3.2.21",
8
- "4.0.13"
7
+ "4.2.6"
9
8
  ]
10
9
 
11
10
  def run_tests_for_version(version)
@@ -16,7 +15,7 @@ def run_tests_for_version(version)
16
15
  commands << "bundle install"
17
16
  commands << "bundle exec rspec"
18
17
 
19
- system({'RAILS_VERSION' => version}, commands.join(';'))
18
+ system({'RAILS_VERSION' => version}, commands.join(' && '))
20
19
  end
21
20
 
22
21
  task :all do
@@ -24,13 +23,15 @@ task :all do
24
23
  puts "Testing gem for rails version: #{version}"
25
24
  success = run_tests_for_version(version)
26
25
 
27
- if not success
26
+ unless success
28
27
  puts "Test suite aborted, errors occured."
29
28
  exit($?.exitstatus)
30
29
  end
31
30
  end
32
31
  end
33
32
 
34
- task :default do
35
- run_tests_for_version(ENV['RAILS_VERSION'] || '3.2.21')
36
- end
33
+ # task :default do
34
+ # run_tests_for_version(ENV['RAILS_VERSION'] || '4.2.6')
35
+ # end
36
+
37
+ task default: :spec
@@ -0,0 +1 @@
1
+ require 'sparrow'
@@ -21,7 +21,7 @@ module Sparrow
21
21
  @json_request_format_header = 'request-json-format'
22
22
  @json_response_format_header = 'response-json-format'
23
23
  @excluded_routes = []
24
- @default_json_request_key_transformation_strategy = :camelize
24
+ @default_json_request_key_transformation_strategy = :underscore
25
25
  @default_json_response_key_transformation_strategy = :camelize
26
26
  @camelize_ignore_uppercase_keys = true
27
27
  @allowed_content_types = %w[
@@ -35,6 +35,10 @@ module Sparrow
35
35
  @camelize_strategy = :lower
36
36
  end
37
37
 
38
+ def active_support_legacy_version
39
+ /3\.\d+\.\d+/
40
+ end
41
+
38
42
  ##
39
43
  # @param type [String] the http message type.
40
44
  # Must be either 'request' or 'response'.
@@ -1,23 +1,28 @@
1
- class Hash
2
- # Defines deep_transform_keys as available in ActiveSupport >= 4.0.2.
3
- # See {http://apidock.com/rails/v4.2.1/Hash/deep_transform_keys}
4
- def deep_transform_keys(&block)
5
- deep_transform_in_object(self, &block)
6
- end
1
+ module Sparrow
2
+ module CoreExt
3
+ module Hash
4
+ refine ::Hash do
5
+ # Defines deep_transform_keys as available in ActiveSupport >= 4.0.2.
6
+ # See {http://apidock.com/rails/v4.2.1/Hash/deep_transform_keys}
7
+ def deep_transform_keys(&block)
8
+ deep_transform_in_object(self, &block)
9
+ end
7
10
 
8
- private
11
+ private
9
12
 
10
- def deep_transform_in_object(obj, &block)
11
- case obj
12
- when Hash
13
- obj.each_with_object({}) do |(key,value), result|
14
- result[yield(key)] = deep_transform_in_object(value, &block)
13
+ def deep_transform_in_object(obj, &block)
14
+ case obj
15
+ when ::Hash
16
+ obj.each_with_object({}) do |(key,value), result|
17
+ result[yield(key)] = deep_transform_in_object(value, &block)
18
+ end
19
+ when Array
20
+ obj.map { |el| deep_transform_in_object(el, &block) }
21
+ else
22
+ obj
23
+ end
15
24
  end
16
- when Array
17
- obj.map { |el| deep_transform_in_object(el, &block) }
18
- else
19
- obj
25
+ end
20
26
  end
21
27
  end
22
28
  end
23
-
@@ -2,14 +2,23 @@ require 'active_support/core_ext/object'
2
2
  require 'active_support/core_ext/string'
3
3
  require 'active_support/version'
4
4
 
5
- if ActiveSupport::VERSION::STRING.match(/3\.\d+\.\d+/)
5
+ module Sparrow
6
+ module_function
7
+
8
+ def uses_active_support_legacy_version?
9
+ active_support_legacy_version = /3\.\d+\.\d+/
10
+ ActiveSupport::VERSION::STRING.match(active_support_legacy_version)
11
+ end
12
+ end
13
+
14
+ if Sparrow.uses_active_support_legacy_version?
6
15
  require 'sparrow/core_ext/hash'
7
16
  require 'active_support/core_ext/object/to_param'
8
17
  require 'active_support/core_ext/object/to_query'
9
18
  end
10
19
 
11
20
  unless defined?(Rails)
12
- require 'active_support/core_ext/logger'
21
+ require 'active_support/logger'
13
22
  end
14
23
 
15
24
  require 'singleton'
@@ -39,7 +39,7 @@ module Sparrow
39
39
  # @param [Boolean] enabled logging enabled
40
40
  def initialize(enabled)
41
41
  self.enabled = enabled
42
- @logger = if defined?(Rails) then
42
+ @logger = if defined?(Rails)
43
43
  Rails.logger
44
44
  else
45
45
  ::Logger.new(STDOUT)
@@ -2,10 +2,10 @@ module Sparrow
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'sparrow.insert_middleware' do |app|
4
4
  # handle request
5
- app.config.middleware.insert_after 'Rails::Rack::Logger',
6
- 'Sparrow::RequestMiddleware'
5
+ app.config.middleware.insert_after Rails::Rack::Logger,
6
+ Sparrow::RequestMiddleware
7
7
  # handle response
8
- app.config.middleware.use 'Sparrow::ResponseMiddleware'
8
+ app.config.middleware.use Sparrow::ResponseMiddleware
9
9
  end
10
10
  end
11
11
  end
@@ -16,7 +16,7 @@ module Sparrow
16
16
  # The HTTP Content Type Field
17
17
  # @return [String] the HTTP Content Type
18
18
  def content_type
19
- request.content_type || super
19
+ request.content_type.presence || super
20
20
  end
21
21
  end
22
22
  end
@@ -15,14 +15,14 @@ module Sparrow
15
15
  private
16
16
 
17
17
  def steward
18
+ configuration = Sparrow.configuration
18
19
  ResponseSteward.new(http_message,
19
- allowed_content_types: Sparrow.configuration.allowed_content_types,
20
- allowed_accepts: Sparrow.configuration.allowed_accepts,
21
- excluded_routes: Sparrow.configuration.excluded_routes,
22
- ignored_response_codes: Sparrow.configuration.ignored_response_codes)
20
+ allowed_content_types: configuration.allowed_content_types,
21
+ allowed_accepts: configuration.allowed_accepts,
22
+ excluded_routes: configuration.excluded_routes,
23
+ ignored_response_codes: configuration.ignored_response_codes)
23
24
  end
24
25
 
25
-
26
26
  def converted_response_body
27
27
  # return the original body if we are not going to process it
28
28
  return body unless steward.has_processable_http_message?
@@ -29,7 +29,7 @@ module Sparrow
29
29
  # @see #exclude?
30
30
  # @see #excluded_routes
31
31
  def allow?(path)
32
- not exclude?(path)
32
+ !exclude?(path)
33
33
  end
34
34
 
35
35
  ##
@@ -46,8 +46,8 @@ module Sparrow
46
46
  input = @env[HttpMessage::RACK_INPUT_KEY].gets
47
47
 
48
48
  begin
49
- @env[HttpMessage::FORM_HASH_KEY] = MultiJson.load(input)
50
- rescue MultiJson::ParseError
49
+ @env[HttpMessage::FORM_HASH_KEY] = JSON.parse(input)
50
+ rescue JSON::ParserError
51
51
  # ignore
52
52
  ensure
53
53
  @env[HttpMessage::RACK_INPUT_KEY].rewind
@@ -11,7 +11,7 @@ module Sparrow
11
11
  # fallback.
12
12
  # @param [Object] input the JSON input
13
13
  # @return [Boolean] True
14
- def match?(input)
14
+ def match?(_input)
15
15
  true
16
16
  end
17
17
 
@@ -9,7 +9,7 @@ module Sparrow
9
9
  class JsonFormatStrategy
10
10
  ##
11
11
  # Empty constructor. Does nothing.
12
- def initialize(*args)
12
+ def initialize(*_args)
13
13
  end
14
14
 
15
15
  ##
@@ -29,22 +29,23 @@ module Sparrow
29
29
  # i.e. an Array, a String or a RackBody
30
30
  # @return [String] the formatted JSON
31
31
  def self.convert(body)
32
- strategy = json_format_strategies.detect do |strategy|
33
- strategy.match?(body)
32
+ strategy = json_format_strategies.detect do |strategy_candidate|
33
+ strategy_candidate.match?(body)
34
34
  end
35
35
  strategy.convert(body)
36
36
  end
37
37
 
38
- private
39
38
  def self.init(*args)
40
39
  @@json_format_strategies ||= Array.new(args)
41
40
  end
41
+ private_class_method :init
42
42
 
43
43
  def self.json_format_strategies
44
44
  init
45
45
  default = Sparrow::Strategies::DefaultJsonFormatStrategy.instance
46
46
  @@json_format_strategies.reject(&:blank?) + [default]
47
47
  end
48
+ private_class_method :json_format_strategies
48
49
  end
49
50
  end
50
51
  end
@@ -7,7 +7,7 @@ module Sparrow
7
7
  ##
8
8
  # Create a new UnderscoreKey Strategy
9
9
  # Does nothing except returning a plain instance.
10
- def initialize(*args)
10
+ def initialize(*_args)
11
11
  # no initialization needed
12
12
  end
13
13
 
@@ -3,6 +3,10 @@ module Sparrow
3
3
  ##
4
4
  # Core class to trigger the conversion
5
5
  class TransformParams
6
+ if Sparrow.uses_active_support_legacy_version?
7
+ using Sparrow::CoreExt::Hash
8
+ end
9
+
6
10
  ##
7
11
  # the strategy stating how to convert the JSON
8
12
  # @return [KeyTransformation] key transformation strategy
@@ -51,7 +55,7 @@ module Sparrow
51
55
  private
52
56
 
53
57
  def create_key_transformation_strategy(key_transformation_strategy)
54
- class_name = "#{key_transformation_strategy.to_s}_key"
58
+ class_name = "#{key_transformation_strategy}_key"
55
59
  class_name = class_name.camelize
56
60
  full_strategy_class_name =
57
61
  "Sparrow::Strategies::KeyTransformation::#{class_name}"
@@ -16,10 +16,10 @@ module Sparrow
16
16
 
17
17
  def json_body
18
18
  json = parsable_json_string(transform_params)
19
- MultiJson.load(json)
19
+ JSON.parse(json)
20
20
  json
21
- rescue MultiJson::ParseError
22
- MultiJson.dump(ensure_json)
21
+ rescue JSON::ParserError
22
+ JSON.generate(ensure_json)
23
23
  end
24
24
 
25
25
  private
@@ -38,19 +38,19 @@ module Sparrow
38
38
  json_params = if !params.is_a?(Hash)
39
39
  Sparrow::Strategies::JsonFormatStrategy.convert(params)
40
40
  elsif params.is_a?(Hash) &&
41
- params.values == [nil] &&
42
- params.keys.length == 1
41
+ params.values.compact.empty? &&
42
+ params.keys.one?
43
43
  params.keys.first
44
44
  else
45
45
  params
46
46
  end
47
- return MultiJson.load(json_params) if json_params.is_a?(String)
47
+ return JSON.parse(json_params) if json_params.is_a?(String)
48
48
  json_params
49
49
  end
50
50
 
51
51
  def parsable_json_string(transformable_params)
52
52
  if [Hash, Array].include? transformable_params.class
53
- MultiJson.dump(transformable_params)
53
+ JSON.generate(transformable_params)
54
54
  else
55
55
  transformable_params
56
56
  end
@@ -67,7 +67,7 @@ module Sparrow
67
67
  end
68
68
 
69
69
  ##
70
- # Usualy Query String parameters want to get transformed as well
70
+ # Usually Query String parameters want to get transformed as well
71
71
  def transform_query_string
72
72
  env_query_hash = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
73
73
  transformed_hash = transform_params_strategy.transform(env_query_hash)
@@ -1,3 +1,3 @@
1
1
  module Sparrow
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
- rails_version = ENV["RAILS_VERSION"] || "3.2.21"
3
+ rails_version = ENV["RAILS_VERSION"] || "4.2.6"
4
+ ruby_version = File.open(File.join(__dir__, '.ruby-version')).read.chomp
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'sparrow/version'
6
7
 
@@ -17,19 +18,20 @@ supported.
17
18
  }
18
19
  spec.homepage = "https://github.com/GateprotectGmbH/sparrow"
19
20
  spec.license = "MIT"
21
+ spec.required_ruby_version = ">= #{ruby_version}"
20
22
 
21
23
  spec.files = `git ls-files -z`.split("\x0")
22
24
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
26
  spec.require_paths = ["lib"]
25
27
 
26
- spec.add_runtime_dependency "activesupport", ">= 3.2.17"
28
+ spec.add_runtime_dependency "activesupport", "<= 4.2.6"
29
+
27
30
  spec.add_development_dependency "pry"
28
31
  spec.add_development_dependency "bundler", "~> 1.5"
29
32
  spec.add_development_dependency "rake"
30
33
  spec.add_development_dependency "rspec", '~> 3'
31
34
  spec.add_development_dependency "rspec-its"
32
35
  spec.add_development_dependency "rack-test"
33
- spec.add_development_dependency "multi_json"
34
36
  spec.add_development_dependency "rails", rails_version
35
37
  end
@@ -1,17 +1,34 @@
1
1
  class App
2
2
 
3
3
  def call(env)
4
+ @env = env
4
5
  params = env["rack.input"].gets
5
- response = Rack::Response.new
6
- response['Content-Type'] = 'application/json'
7
- response.write(json_response(params))
6
+ @params = JSON.parse(params || '{}')
7
+ header = {
8
+ 'Content-Type' => 'application/json',
9
+ 'Accept' => 'application/json'
10
+ }
11
+
12
+ response = Rack::Response.new(
13
+ json_response(params),
14
+ status,
15
+ header)
8
16
  response.finish
9
17
  end
10
18
 
11
19
  private
12
20
 
21
+ def status
22
+ path = @env['PATH_INFO']
23
+ if path =~ /error$/
24
+ @params['error_code'] || 500
25
+ else
26
+ 200
27
+ end
28
+ end
29
+
13
30
  def json_response(params)
14
- hsh_params = MultiJson.load(params)
31
+ hsh_params = @params
15
32
  keys = hsh_params.reduce([]) do |result, (key, value)|
16
33
  result << key
17
34
  if value.is_a?(Hash)
@@ -19,7 +36,7 @@ class App
19
36
  end
20
37
  result
21
38
  end.flatten
22
- MultiJson.dump({
39
+ JSON.generate({
23
40
  keys: keys,
24
41
  fakeKey: true,
25
42
  fake_key: false