json-rpc2rest 0.1.1 → 0.1.2

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: 0dfebc592bfacf40c0991ebe2b6683f50c6a70e2
4
- data.tar.gz: 00c4a5615992acbfa2caf6e6474d74ce514ab067
3
+ metadata.gz: 47d37f832ed11a5c5e4bbc6ca806c70fdf06238d
4
+ data.tar.gz: 1d2f093b6778dd138ad5b4214ef0f303e7dcb0a6
5
5
  SHA512:
6
- metadata.gz: 6da9431dddee9f6fd7951ba2357fe251fd0f717ef7f0bbabadfae8be4b533a668cf78dfebaf155ae75f205c18df43a09774d375cef908a0988351c0e8f47c2c0
7
- data.tar.gz: 4f34e693b794727ebae17cb6d523159d46c8693b0ca49d01c6cc13baa6de29db8f1fe61ba402f02ae47dfe9b7893acea981c85547321eb6737107b662030e388
6
+ metadata.gz: ee76445109e8d883c9b7db9172cbf0f985936e51c02ffc1d55dc41981881dd3a3a86ad411c898549a6d2d413074da4d4d4468e090208a1d83cc05e1023929d7b
7
+ data.tar.gz: 209347af0bab50fa0b10991178d85fc3178c0f0e91b408667cbba0f13efa0c5c8e72654be1993cf3c05f8ed9582532b5882bfd0fc1c094b402c0b6eeb42d150b
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --backtrace
3
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
6
+ - 1.9
7
+ - jruby
8
+ - rbx
9
+ - ruby-head
10
+ - jruby-head
11
+ - rbx-head
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
16
+ - rvm: rbx-head
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack', '>= 0.4'
4
+ gem 'rake'
5
+
6
+ group :test do
7
+ gem 'rspec', '~> 3.2'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ rack (1.6.0)
6
+ rake (10.4.2)
7
+ rspec (3.2.0)
8
+ rspec-core (~> 3.2.0)
9
+ rspec-expectations (~> 3.2.0)
10
+ rspec-mocks (~> 3.2.0)
11
+ rspec-core (3.2.2)
12
+ rspec-support (~> 3.2.0)
13
+ rspec-expectations (3.2.0)
14
+ diff-lcs (>= 1.2.0, < 2.0)
15
+ rspec-support (~> 3.2.0)
16
+ rspec-mocks (3.2.1)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.2.0)
19
+ rspec-support (3.2.2)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ rack (>= 0.4)
26
+ rake
27
+ rspec (~> 3.2)
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Json-Rpc To Rest
2
+
3
+ Middleware to make inner redirect for [Json-Rpc](http://en.wikipedia.org/wiki/JSON-RPC) requests.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/json-rpc2rest.png)](http://badge.fury.io/rb/json-rpc2rest)
6
+ [![Build Status](https://travis-ci.org/dzjuck/json-rpc2rest.svg?branch=master)](https://travis-ci.org/dzjuck/json-rpc2rest)
7
+
8
+ ## Installation
9
+
10
+ ```shell
11
+ gem install json-rpc2rest
12
+ ```
13
+
14
+ or add the following line to Gemfile:
15
+
16
+ ```ruby
17
+ gem 'json-rpc2rest'
18
+ ```
19
+
20
+ and run `bundle install` from your shell.
21
+
22
+ After that add line to `config/application.rb`
23
+
24
+ ```ruby
25
+ config.middleware.use 'Json-Rpc2Rest'
26
+ ```
27
+
28
+ Also you can specify field with method name
29
+
30
+ ```ruby
31
+ config.middleware.use 'Json-Rpc2Rest', field: 'requestMethod'
32
+ ```
33
+
34
+ Default field is `"method"` as in [specification](http://www.jsonrpc.org/specification#request_object).
35
+
36
+ ## Example
37
+
38
+ ```ruby
39
+ # config/application.rb
40
+ config.middleware.use 'JsonRpcToRest'
41
+ ```
42
+
43
+ Post request to `/api` with params
44
+ ```json
45
+ {"method": "get_posts_list", "data": [], "id": 2}
46
+ ```
47
+ will be processed as `/api/get_posts_list` with same params.
48
+
49
+ ## Tests
50
+
51
+ ```bash
52
+ git clone https://github.com/dzjuck/json-rpc2rest.git
53
+ cd json-rpc2rest
54
+ bundle install
55
+ rspec
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ desc 'Run the specs'
6
+ RSpec::Core::RakeTask.new do |r|
7
+ r.verbose = false
8
+ end
9
+
10
+ task :test => :spec
11
+ task :default => [:spec]
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+
5
+ s.name = "json-rpc2rest"
6
+ s.version = "0.1.2"
7
+ s.date = "2015-03-28"
8
+
9
+ s.summary = "Json-Rpc to Rest middleware."
10
+ s.description = "Json-Rpc to Rest middleware."
11
+ s.authors = ["Ilya Lavrov"]
12
+ s.email = "dzjuck@gmail.com"
13
+ s.homepage = "http://github.com/dzjuck/json-rpc2rest"
14
+ s.files = `git ls-files`.split("\n")
15
+
16
+ s.require_paths = %w[lib]
17
+ s.rubygems_version = '1.1.1'
18
+ s.license = 'MIT'
19
+ end
data/lib/json-rpc2rest.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'rack'
2
3
 
3
4
  class JsonRpc2Rest
4
5
  def initialize(app, options={})
@@ -21,7 +22,7 @@ private
21
22
  @path = nil
22
23
 
23
24
  req_body = Rack::Request.new(env).body.read
24
- if env['REQUEST_METHOD'] == 'POST' && req_body.present?
25
+ if env['REQUEST_METHOD'] == 'POST' && !req_body.nil? && !req_body.empty?
25
26
  # @params = @env['rack.request.form_hash']
26
27
  @params = JSON.parse(req_body)
27
28
  else
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require 'json-rpc2rest'
3
3
 
4
4
  shared_examples_for 'change env' do
@@ -18,6 +18,11 @@ end
18
18
  describe JsonRpc2Rest do
19
19
  let(:obj) { described_class.new(app) }
20
20
  let(:app) { double('app') }
21
+ let(:params) { '' }
22
+ before(:each) do
23
+ allow_any_instance_of(Rack::Request).
24
+ to receive_message_chain(:body, :read).and_return(params)
25
+ end
21
26
 
22
27
  it 'takes a backend and returns a middleware component' do
23
28
  expect(obj).to respond_to(:call)
@@ -29,10 +34,10 @@ describe JsonRpc2Rest do
29
34
  end
30
35
 
31
36
  context 'when json-rpc params' do
32
- let(:params) { {'method'=>'get_posts_list', 'data' => [], 'id'=>'2'} }
37
+ let(:params) { {'method'=>'get_posts_list', 'data' => [], 'id'=>'2'}.to_json }
33
38
  let(:env) {
34
39
  {'REQUEST_METHOD' => 'POST',
35
- 'rack.request.form_hash' => params,
40
+ # 'rack.request.form_hash' => params,
36
41
  'PATH_INFO' => '/api',
37
42
  'REQUEST_URI' => '/api?page=2'
38
43
  }
@@ -49,7 +54,7 @@ describe JsonRpc2Rest do
49
54
  context 'when PATH_INFO with trailing slash' do
50
55
  let(:env) {
51
56
  {'REQUEST_METHOD' => 'POST',
52
- 'rack.request.form_hash' => params,
57
+ # 'rack.request.form_hash' => params,
53
58
  'PATH_INFO' => '/api/',
54
59
  'REQUEST_URI' => '/api/?page=2'
55
60
  }
@@ -59,13 +64,13 @@ describe JsonRpc2Rest do
59
64
  end
60
65
 
61
66
  context 'when method is not defined in params' do
62
- let(:params) { {'data' => [], 'id'=>'2'} }
67
+ let(:params) { {'data' => [], 'id'=>'2'}.to_json }
63
68
 
64
69
  it_should_behave_like "don't change env"
65
70
  end
66
71
 
67
72
  context 'when method field changed' do
68
- let(:params) { {'requestMethod'=>'get_posts_list', 'data' => [], 'id'=>'2'} }
73
+ let(:params) { {'requestMethod'=>'get_posts_list', 'data' => [], 'id'=>'2'}.to_json }
69
74
  let(:obj) { described_class.new(app, {field: 'requestMethod'}) }
70
75
  it_should_behave_like 'change env'
71
76
  end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-rpc2rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Lavrov
@@ -16,8 +16,17 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - ".gitignore"
20
+ - ".rspec"
21
+ - ".travis.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - README.md
25
+ - Rakefile
26
+ - json-rpc2rest.gemspec
19
27
  - lib/json-rpc2rest.rb
20
- - spec/json-rpc2rest_spec.rb
28
+ - spec/lib/json-rpc2rest_spec.rb
29
+ - spec/spec_helper.rb
21
30
  homepage: http://github.com/dzjuck/json-rpc2rest
22
31
  licenses:
23
32
  - MIT
@@ -42,5 +51,5 @@ rubygems_version: 2.4.6
42
51
  signing_key:
43
52
  specification_version: 2
44
53
  summary: Json-Rpc to Rest middleware.
45
- test_files:
46
- - spec/json-rpc2rest_spec.rb
54
+ test_files: []
55
+ has_rdoc: