restful_celluloid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 731ddae66a593df21315d3db3ba7c3b0a7986583
4
+ data.tar.gz: 61d64be771428bd901bcc275e1664c0f90093ecf
5
+ SHA512:
6
+ metadata.gz: 704b32c361cc54ba7b4216aa0606e10593bf343bfff54b6d2d0d94eec95417809f87efb936464576e7d3ce7f786ebf676639cbd0b92d1eb76c026a38bf173abb
7
+ data.tar.gz: b664d1fb37b463bfb8ea1d4b912dbec7967f1e25a85b78e40d12ff910bd767df82fef22895fda0b63d39172d958eefdc292d7c1ef0261310eee0be9ca1f073ee
data/.autotest ADDED
@@ -0,0 +1,3 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ %w{.git vendor spec/integration coverage}.each {|exception| at.add_exception(exception)}
3
+ end
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in restful_celluloid.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dragan Milic
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # RestfulCelluloid
2
+
3
+ RestfulCelluloid is a simple RESTful interface to the celluloid actors. It offers a technology independent communication layer (JSON over HTTP) that can interact directly with Celluloid actors.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'restful_celluloid'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install restful_celluloid
19
+
20
+ ## Usage
21
+ Minimal example:
22
+
23
+ require 'restful_celluloid'
24
+
25
+ class MyActor
26
+ include Celluloid
27
+
28
+ def simple_method
29
+ "some_result"
30
+ end
31
+
32
+ end
33
+
34
+ MyActor.supervise_as :my_actor
35
+
36
+ RestfulCelluloid.start! 12345
37
+
38
+ Now you can call the service:
39
+
40
+ curl http://localhost:12345/actor/my_actor/simple_method
41
+
42
+ Result:
43
+
44
+ "some_result"
45
+
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --color --strict
@@ -0,0 +1,26 @@
1
+ Feature: invoking actor methods using GET requests
2
+
3
+ Scenario: invoking method without parameters - happy path
4
+ Given there is an actor registered
5
+ When I call an existing method without parameters using GET method
6
+ Then I should receive result of the method call in the response
7
+
8
+ Scenario: invoking method with parameters - happy path
9
+ Given there is an actor registered
10
+ When I call an existing method with parameters using GET method
11
+ Then I should receive result of the parametrized method call in the response
12
+
13
+ Scenario: invoking method that raises exception
14
+ Given there is an actor registered
15
+ When I call an existing method that raises an exception using GET method
16
+ Then I should receive 500 status code and an error object containing message "Method execution raised exception."
17
+ And the response should contain exception message and back trace
18
+
19
+ Scenario: reporting error when actor is not registered
20
+ When I call a method without parameters on a non-existing actor using GET method
21
+ Then I should receive 404 status code and an error object containing message "Actor 'wrong_actor' not found."
22
+
23
+ Scenario: invoking method when method does not exist
24
+ Given there is an actor registered
25
+ When I call an non-existing method without parameters using GET method
26
+ Then I should receive 404 status code and an error object containing message "Method 'wrong_method' not found on actor 'my_actor'."
@@ -0,0 +1,6 @@
1
+ Feature: list of actors
2
+
3
+ Scenario: list of actors
4
+ Given there is an actor registered
5
+ When I request list of actors
6
+ Then the registered actor should be in the list
@@ -0,0 +1,46 @@
1
+ When(/^I call an existing method without parameters using GET method$/) do
2
+ invoke_on_actor :my_actor, :simple_method
3
+ end
4
+
5
+ Then(/^I should receive result of the method call in the response$/) do
6
+ @result.code.should == 200
7
+ @result.body.should == "\"some_result\""
8
+ end
9
+
10
+ Then(/^I should receive result of the parametrized method call in the response$/) do
11
+ @result.code.should == 200
12
+ @result['param1'].should == 'abc'
13
+ end
14
+
15
+
16
+ When(/^I call a method without parameters on a not\-existing actor using GET method$/) do
17
+ invoke_on_actor :wrong_actor, :simple_method
18
+ end
19
+
20
+ Then(/^I should receive (\d+) status code and an error object containing message "(.*?)"$/) do |expected_code, expected_message|
21
+ @result.code.should == expected_code.to_i
22
+ JSON.parse(@result.body)['error'].should == expected_message
23
+ end
24
+
25
+
26
+ When(/^I call an non\-existing method without parameters using GET method$/) do
27
+ invoke_on_actor :my_actor, :wrong_method
28
+ end
29
+
30
+ When(/^I call a method without parameters on a non\-existing actor using GET method$/) do
31
+ invoke_on_actor :wrong_actor, :simple_method
32
+ end
33
+
34
+ When(/^I call an existing method with parameters using GET method$/) do
35
+ invoke_on_actor :my_actor, :method_with_params, param1: 'abc'
36
+ end
37
+
38
+ When(/^I call an existing method that raises an exception using GET method$/) do
39
+ invoke_on_actor :my_actor, :exception_raising_method
40
+ end
41
+
42
+ Then(/^the response should contain exception message and back trace$/) do
43
+ error_body=JSON.parse(@result.body)
44
+ error_body['message'].should == 'oops!'
45
+ error_body['backtrace'].should be_a Array
46
+ end
@@ -0,0 +1,11 @@
1
+ Given(/^there is an actor registered$/) do
2
+ register_an_actor
3
+ end
4
+
5
+ When(/^I request list of actors$/) do
6
+ @actors=get_list_of_actors
7
+ end
8
+
9
+ Then(/^the registered actor should be in the list$/) do
10
+ @actors.should include('my_actor')
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'restful_celluloid'
2
+ require 'httparty'
3
+
4
+ Before do
5
+ RestfulCelluloid.start 31337
6
+ end
7
+
8
+
9
+ After do
10
+ RestfulCelluloid.stop
11
+ end
12
+
13
+ class MyActor
14
+ include Celluloid
15
+
16
+ def simple_method
17
+ "some_result"
18
+ end
19
+
20
+ def method_with_params params
21
+ params
22
+ end
23
+
24
+ def exception_raising_method
25
+ raise "oops!"
26
+ end
27
+ end
28
+
29
+ def register_an_actor
30
+ MyActor.supervise_as :my_actor
31
+ end
32
+
33
+ def get_list_of_actors
34
+ HTTParty.get("http://localhost:31337/actors")
35
+ end
36
+
37
+ def invoke_on_actor actor, method_name, params={}
38
+ @result=HTTParty.get("http://localhost:31337/actor/%s/%s" % [actor.to_s, method_name.to_s], {query: params})
39
+ end
@@ -0,0 +1,3 @@
1
+ module RestfulCelluloid
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,69 @@
1
+ require "restful_celluloid/version"
2
+ require 'webrick'
3
+ require 'sinatra/base'
4
+ require 'thread'
5
+ require 'celluloid'
6
+ require 'json'
7
+
8
+ module RestfulCelluloid
9
+
10
+
11
+ def self.start! port
12
+ RESTfulServer.port=port
13
+ RESTfulServer.run!
14
+ end
15
+
16
+ def self.start port
17
+ @port=port
18
+ RESTfulServer.port=port
19
+ server_queue=Queue.new
20
+ Thread.new do
21
+ RESTfulServer.run! do |server|
22
+ server_queue << server
23
+ end
24
+ end
25
+ @server=server_queue.pop
26
+ end
27
+
28
+ def self.stop
29
+ @server.shutdown
30
+ end
31
+
32
+ class RESTfulServer < ::Sinatra::Base
33
+ set :server, %w[webrick]
34
+ set :server_settings, Logger: WEBrick::Log.new("/dev/null")
35
+
36
+ get '/actors' do
37
+ content_type :json
38
+ Celluloid::Actor.all.map{|actor| actor.name}.to_json
39
+ end
40
+
41
+ get '/actor/:actor_name/:method_name' do
42
+ content_type :json
43
+ actor_name=params[:actor_name]
44
+ method_name=params[:method_name]
45
+ actor=Celluloid::Actor[actor_name]
46
+ if actor
47
+ if actor.respond_to? method_name
48
+ begin
49
+ params=request.env['rack.request.query_hash']
50
+ result=params.empty? ? actor.send(method_name) : actor.send(method_name,params)
51
+ result.to_json
52
+ rescue => ex
53
+ status 500
54
+ {error: 'Method execution raised exception.', message: ex.message, backtrace: ex.backtrace}.to_json
55
+ end
56
+ else
57
+ status 404
58
+ return {error: ("Method '%s' not found on actor '%s'." % [method_name, actor_name])}.to_json
59
+ end
60
+ else
61
+ status 404
62
+ return {error: ("Actor '%s' not found." % actor_name)}.to_json
63
+ end
64
+ end
65
+
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'restful_celluloid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "restful_celluloid"
8
+ spec.version = RestfulCelluloid::VERSION
9
+ spec.authors = ["Dragan Milic"]
10
+ spec.email = ["dragan@netice9.com"]
11
+ spec.description = %q{RESTful interface for celluloid actor framework}
12
+ spec.summary = %q{RESTful interface for celluloid actor framework}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "autotest"
25
+ spec.add_development_dependency "cucumber"
26
+ spec.add_development_dependency "httparty"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_dependency "sinatra"
30
+ spec.add_dependency "celluloid"
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module RestfulCelluloid
4
+ describe "start/stop methods" do
5
+ it "should start/stop server on the specified port" do
6
+ RestfulCelluloid::start 31337
7
+ socket=TCPSocket.new 'localhost', 31337
8
+ socket.close
9
+ RestfulCelluloid::stop
10
+ end
11
+ end
12
+
13
+
14
+ class MyActor
15
+ include Celluloid
16
+
17
+ def simple_method
18
+ "some_result"
19
+ end
20
+ end
21
+
22
+ describe RESTfulServer do
23
+ before do
24
+ RestfulCelluloid::start 31337
25
+ MyActor.supervise_as :my_actor
26
+ end
27
+ after {RestfulCelluloid::stop}
28
+ it "should list actors" do
29
+ result=HTTParty.get('http://localhost:31337/actors')
30
+ result.code.should == 200
31
+ result.content_type.should include 'application/json'
32
+ result.should include('my_actor')
33
+ end
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,6 @@
1
+ require 'simplecov'
2
+ require 'httparty'
3
+ SimpleCov.start
4
+ require 'restful_celluloid'
5
+
6
+
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restful_celluloid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dragan Milic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: autotest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sinatra
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: celluloid
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: RESTful interface for celluloid actor framework
154
+ email:
155
+ - dragan@netice9.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .autotest
161
+ - .gitignore
162
+ - .rspec
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - cucumber.yml
168
+ - features/invoke_method_using_get.feature
169
+ - features/list_of_actors.feature
170
+ - features/step_definitions/invoke_method_using_get_steps.rb
171
+ - features/step_definitions/list_of_actors_steps.rb
172
+ - features/support/env.rb
173
+ - lib/restful_celluloid.rb
174
+ - lib/restful_celluloid/version.rb
175
+ - restful_celluloid.gemspec
176
+ - spec/restful_celluloid_spec.rb
177
+ - spec/spec_helper.rb
178
+ homepage: ''
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.0.3
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: RESTful interface for celluloid actor framework
202
+ test_files:
203
+ - features/invoke_method_using_get.feature
204
+ - features/list_of_actors.feature
205
+ - features/step_definitions/invoke_method_using_get_steps.rb
206
+ - features/step_definitions/list_of_actors_steps.rb
207
+ - features/support/env.rb
208
+ - spec/restful_celluloid_spec.rb
209
+ - spec/spec_helper.rb