rpcoder 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +16 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +21 -0
- data/README.rdoc +21 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rpcoder.rb +92 -0
- data/lib/rpcoder/function.rb +41 -0
- data/lib/rpcoder/type.rb +49 -0
- data/lib/templates/API.erb +147 -0
- data/lib/templates/Type.erb +39 -0
- data/mock/build.xml +70 -0
- data/mock/lib/as3corelib.swc +0 -0
- data/mock/lib/flexUnitTasks-4.0.0.jar +0 -0
- data/mock/lib/flexunit-4.0.0.swc +0 -0
- data/mock/lib/flexunit-cilistener-4.0.0.swc +0 -0
- data/mock/lib/flexunit-flexcoverlistener-4.0.0.swc +0 -0
- data/mock/lib/flexunit-uilistener-4.0.0.swc +0 -0
- data/mock/lib/hamcrest-as3-1.1.1.swc +0 -0
- data/mock/lib/mockolate-0.9.3.swc +0 -0
- data/mock/mock_rpcoder.rb +46 -0
- data/mock/mock_server.rb +34 -0
- data/mock/src/Mock.mxml +62 -0
- data/mock/src_test/FlexUnitRunner.mxml +27 -0
- data/mock/src_test/TestSuite.as +10 -0
- data/mock/src_test/com/oneup/rpcoder/test/APITest.as +76 -0
- data/mock/src_test/com/oneup/rpcoder/test/TypeTest.as +25 -0
- data/rpcoder.gemspec +92 -0
- data/spec/fixtures/foo/bar/API.as +139 -0
- data/spec/fixtures/foo/bar/Mail.as +34 -0
- data/spec/rpcoder/function_spec.rb +52 -0
- data/spec/rpcoder_spec.rb +46 -0
- data/spec/spec_helper.rb +12 -0
- metadata +158 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
/* generated by rpcoder */
|
2
|
+
|
3
|
+
package foo.bar
|
4
|
+
{
|
5
|
+
import mx.rpc.AsyncResponder;
|
6
|
+
import mx.rpc.AsyncToken;
|
7
|
+
import mx.rpc.events.ResultEvent;
|
8
|
+
import mx.rpc.events.FaultEvent;
|
9
|
+
import mx.rpc.http.HTTPService;
|
10
|
+
import com.adobe.serialization.json.JSON;
|
11
|
+
|
12
|
+
public class API
|
13
|
+
{
|
14
|
+
public static const CONTINUE :int = 100;
|
15
|
+
public static const SWITCHING_PROTOCOLS :int = 101;
|
16
|
+
public static const PROCESSING :int = 102;
|
17
|
+
public static const OK :int = 200;
|
18
|
+
public static const CREATED :int = 201;
|
19
|
+
public static const ACCEPTED :int = 202;
|
20
|
+
public static const NON_AUTHORITATIVE_INFORMATION :int = 203;
|
21
|
+
public static const NO_CONTENT :int = 204;
|
22
|
+
public static const RESET_CONTENT :int = 205;
|
23
|
+
public static const PARTIAL_CONTENT :int = 206;
|
24
|
+
public static const MULTI_STATUS :int = 207;
|
25
|
+
public static const IM_USED :int = 226;
|
26
|
+
public static const MULTIPLE_CHOICES :int = 300;
|
27
|
+
public static const MOVED_PERMANENTLY :int = 301;
|
28
|
+
public static const FOUND :int = 302;
|
29
|
+
public static const SEE_OTHER :int = 303;
|
30
|
+
public static const NOT_MODIFIED :int = 304;
|
31
|
+
public static const USE_PROXY :int = 305;
|
32
|
+
public static const RESERVED :int = 306;
|
33
|
+
public static const TEMPORARY_REDIRECT :int = 307;
|
34
|
+
public static const BAD_REQUEST :int = 400;
|
35
|
+
public static const UNAUTHORIZED :int = 401;
|
36
|
+
public static const PAYMENT_REQUIRED :int = 402;
|
37
|
+
public static const FORBIDDEN :int = 403;
|
38
|
+
public static const NOT_FOUND :int = 404;
|
39
|
+
public static const METHOD_NOT_ALLOWED :int = 405;
|
40
|
+
public static const NOT_ACCEPTABLE :int = 406;
|
41
|
+
public static const PROXY_AUTHENTICATION_REQUIRED :int = 407;
|
42
|
+
public static const REQUEST_TIMEOUT :int = 408;
|
43
|
+
public static const CONFLICT :int = 409;
|
44
|
+
public static const GONE :int = 410;
|
45
|
+
public static const LENGTH_REQUIRED :int = 411;
|
46
|
+
public static const PRECONDITION_FAILED :int = 412;
|
47
|
+
public static const REQUEST_ENTITY_TOO_LARGE :int = 413;
|
48
|
+
public static const REQUEST_URI_TOO_LONG :int = 414;
|
49
|
+
public static const UNSUPPORTED_MEDIA_TYPE :int = 415;
|
50
|
+
public static const REQUESTED_RANGE_NOT_SATISFIABLE :int = 416;
|
51
|
+
public static const EXPECTATION_FAILED :int = 417;
|
52
|
+
public static const UNPROCESSABLE_ENTITY :int = 422;
|
53
|
+
public static const LOCKED :int = 423;
|
54
|
+
public static const FAILED_DEPENDENCY :int = 424;
|
55
|
+
public static const UPGRADE_REQUIRED :int = 426;
|
56
|
+
public static const INTERNAL_SERVER_ERROR :int = 500;
|
57
|
+
public static const NOT_IMPLEMENTED :int = 501;
|
58
|
+
public static const BAD_GATEWAY :int = 502;
|
59
|
+
public static const SERVICE_UNAVAILABLE :int = 503;
|
60
|
+
public static const GATEWAY_TIMEOUT :int = 504;
|
61
|
+
public static const HTTP_VERSION_NOT_SUPPORTED :int = 505;
|
62
|
+
public static const VARIANT_ALSO_NEGOTIATES :int = 506;
|
63
|
+
public static const INSUFFICIENT_STORAGE :int = 507;
|
64
|
+
public static const NOT_EXTENDED :int = 510;
|
65
|
+
|
66
|
+
private var _baseUrl:String;
|
67
|
+
private var _errorHandler : Function;
|
68
|
+
|
69
|
+
public function API(baseUrl:String)
|
70
|
+
{
|
71
|
+
this._baseUrl = baseUrl;
|
72
|
+
}
|
73
|
+
|
74
|
+
public function get baseUrl():String
|
75
|
+
{
|
76
|
+
return this._baseUrl;
|
77
|
+
}
|
78
|
+
|
79
|
+
public function set errorHandler(handler : Function):void
|
80
|
+
{
|
81
|
+
this._errorHandler = handler;
|
82
|
+
}
|
83
|
+
|
84
|
+
public function get errorHandler():Function
|
85
|
+
{
|
86
|
+
return this._errorHandler;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* get mail
|
91
|
+
*
|
92
|
+
* @id:int
|
93
|
+
* @foo:String ["A", "B"]
|
94
|
+
* @bar:Array
|
95
|
+
* @baz:Boolean 日本の文字
|
96
|
+
* @success:Function
|
97
|
+
* @error:Function
|
98
|
+
*/
|
99
|
+
public function getMail(id:int, foo:String, bar:Array, baz:Boolean, success:Function, error:Function):void
|
100
|
+
{
|
101
|
+
var params:Object = {"foo":foo, "bar":bar, "baz":baz};
|
102
|
+
request("GET", "/mails/" + id, params,
|
103
|
+
function(e:ResultEvent, t:Object):void {
|
104
|
+
t = t; // FIXME: for removing warning
|
105
|
+
success(new Mail(JSON.decode(e.result as String)));
|
106
|
+
},
|
107
|
+
function(e:FaultEvent, t:Object):void {
|
108
|
+
t = t; // FIXME: for removing warning
|
109
|
+
error(e);
|
110
|
+
}
|
111
|
+
);
|
112
|
+
}
|
113
|
+
|
114
|
+
public function request(method:String, path:String, params:Object, success:Function, error:Function):void
|
115
|
+
{
|
116
|
+
var service:HTTPService = createHttpService(this.baseUrl);
|
117
|
+
service.method = method;
|
118
|
+
service.url = path;
|
119
|
+
service.request = params;
|
120
|
+
service.resultFormat = 'text';
|
121
|
+
var token:AsyncToken = service.send();
|
122
|
+
token.addResponder(new AsyncResponder(
|
123
|
+
success,
|
124
|
+
function(e:FaultEvent, t:Object):void {
|
125
|
+
if (_errorHandler !== null && e.statusCode >= 500) {
|
126
|
+
_errorHandler(e, t);
|
127
|
+
} else {
|
128
|
+
error(e, t);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
));
|
132
|
+
}
|
133
|
+
|
134
|
+
public function createHttpService(baseUrl:String) : HTTPService
|
135
|
+
{
|
136
|
+
return new HTTPService(baseUrl);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/* generated by rpcoder */
|
2
|
+
|
3
|
+
package foo.bar
|
4
|
+
{
|
5
|
+
public class Mail
|
6
|
+
{
|
7
|
+
private var _subject:String;
|
8
|
+
private var _body:String;
|
9
|
+
|
10
|
+
public function get subject():String
|
11
|
+
{
|
12
|
+
return _subject;
|
13
|
+
}
|
14
|
+
|
15
|
+
public function get body():String
|
16
|
+
{
|
17
|
+
return _body;
|
18
|
+
}
|
19
|
+
|
20
|
+
public function Mail(object:Object = null)
|
21
|
+
{
|
22
|
+
if (object)
|
23
|
+
{
|
24
|
+
_subject = object['subject'];
|
25
|
+
_body = object['body'];
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
public function toString():String
|
30
|
+
{
|
31
|
+
return [_subject, _body].join(', ');
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RPCoder
|
4
|
+
describe "Function" do
|
5
|
+
context do
|
6
|
+
before do
|
7
|
+
@function = Function.new
|
8
|
+
@function.name = "getMail"
|
9
|
+
@function.description = "get a mail"
|
10
|
+
@function.path = "/mails/:id" # => ("/mails/" + id)
|
11
|
+
@function.method = "GET"
|
12
|
+
@function.return_type = "Mail"
|
13
|
+
@function.add_param :id, :integer
|
14
|
+
@function.add_param :foo, :string, :expect => ["A","B"]
|
15
|
+
@function.add_param :bar, :array
|
16
|
+
@function.add_param :baz, :boolean, :decription => "日本の文字"
|
17
|
+
end
|
18
|
+
|
19
|
+
{
|
20
|
+
'/mail/:id' => ['"/mail/"', 'id'],
|
21
|
+
'/mail/:id/foo' => ['"/mail/"', 'id', '"/foo"'],
|
22
|
+
'/mail/:mail_id/foo/:id' => ['"/mail/"', 'mail_id', '"/foo/"', 'id'],
|
23
|
+
'/mail/:foo/:bar' => ['"/mail/"', 'foo', '"/"', 'bar'],
|
24
|
+
}.each do |path, path_parts|
|
25
|
+
it "path が #{path} のとき path_parts が #{path_parts.inspect}" do
|
26
|
+
@function.path = path
|
27
|
+
@function.path_parts.should == path_parts
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
{
|
32
|
+
'/mail/:id' => [:foo, :bar, :baz],
|
33
|
+
'/mail/:foo/:id' => [:bar, :baz],
|
34
|
+
}.each do |path, query_params|
|
35
|
+
it "path が #{path} のとき query_params が #{query_params.inspect}" do
|
36
|
+
@function.path = path
|
37
|
+
@function.query_params.map { |i| i.name }.sort.should == query_params.sort
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
[
|
42
|
+
'foo/bar',
|
43
|
+
':foo/bar',
|
44
|
+
].each do |path|
|
45
|
+
it "path が #{path} のとき invalid" do
|
46
|
+
@function.path = path
|
47
|
+
lambda { @function.path_parts }.should raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
describe "RPCoder" do
|
6
|
+
context do
|
7
|
+
before do
|
8
|
+
RPCoder.clear
|
9
|
+
RPCoder.name_space = 'foo.bar'
|
10
|
+
RPCoder.api_class_name = 'API'
|
11
|
+
RPCoder.function "getMail" do |f|
|
12
|
+
f.path = "/mails/:id" # => ("/mails/" + id)
|
13
|
+
f.description = 'get mail'
|
14
|
+
f.method = "GET"
|
15
|
+
f.return_type = "Mail"
|
16
|
+
f.add_param :id, :int
|
17
|
+
f.add_param :foo, :String, :expect => ["A","B"]
|
18
|
+
f.add_param :bar, :Array
|
19
|
+
f.add_param :baz, :Boolean, :description => "日本の文字"
|
20
|
+
end
|
21
|
+
|
22
|
+
RPCoder.type "Mail" do |t|
|
23
|
+
t.add_field :subject, :String
|
24
|
+
t.add_field :body, :String
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it { RPCoder.functions.size.should == 1 }
|
29
|
+
|
30
|
+
it { RPCoder.types.size.should == 1 }
|
31
|
+
|
32
|
+
it 'should render_functions' do
|
33
|
+
expected = File.read(File.expand_path('fixtures/foo/bar/API.as', File.dirname(__FILE__)))
|
34
|
+
RPCoder.render_functions.should == expected
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should render_type' do
|
38
|
+
expected = File.read(File.expand_path('fixtures/foo/bar/Mail.as', File.dirname(__FILE__)))
|
39
|
+
RPCoder.render_type(RPCoder.types.first).should == expected
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'dir_to_export_classes のテスト' do
|
43
|
+
RPCoder.dir_to_export_classes('src').should == "src/foo/bar"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'rpcoder'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpcoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jugyo
|
9
|
+
- Toshiyuki Hirooka
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-04-25 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: sinatra
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rcov
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rake
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
description: Simple RPC generator for as3
|
83
|
+
email: toshi.hirooka@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- lib/rpcoder.rb
|
99
|
+
- lib/rpcoder/function.rb
|
100
|
+
- lib/rpcoder/type.rb
|
101
|
+
- lib/templates/API.erb
|
102
|
+
- lib/templates/Type.erb
|
103
|
+
- mock/build.xml
|
104
|
+
- mock/lib/as3corelib.swc
|
105
|
+
- mock/lib/flexUnitTasks-4.0.0.jar
|
106
|
+
- mock/lib/flexunit-4.0.0.swc
|
107
|
+
- mock/lib/flexunit-cilistener-4.0.0.swc
|
108
|
+
- mock/lib/flexunit-flexcoverlistener-4.0.0.swc
|
109
|
+
- mock/lib/flexunit-uilistener-4.0.0.swc
|
110
|
+
- mock/lib/hamcrest-as3-1.1.1.swc
|
111
|
+
- mock/lib/mockolate-0.9.3.swc
|
112
|
+
- mock/mock_rpcoder.rb
|
113
|
+
- mock/mock_server.rb
|
114
|
+
- mock/src/Mock.mxml
|
115
|
+
- mock/src_test/FlexUnitRunner.mxml
|
116
|
+
- mock/src_test/TestSuite.as
|
117
|
+
- mock/src_test/com/oneup/rpcoder/test/APITest.as
|
118
|
+
- mock/src_test/com/oneup/rpcoder/test/TypeTest.as
|
119
|
+
- rpcoder.gemspec
|
120
|
+
- spec/fixtures/foo/bar/API.as
|
121
|
+
- spec/fixtures/foo/bar/Mail.as
|
122
|
+
- spec/rpcoder/function_spec.rb
|
123
|
+
- spec/rpcoder_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
homepage: http://github.com/one-up/rpcoder
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 1754127494487391921
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.7.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Simple RPC generator for as3
|
155
|
+
test_files:
|
156
|
+
- spec/rpcoder/function_spec.rb
|
157
|
+
- spec/rpcoder_spec.rb
|
158
|
+
- spec/spec_helper.rb
|