rpcoder 0.0.1 → 0.0.2
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/VERSION +1 -1
- data/lib/rpcoder/function.rb +15 -0
- data/lib/rpcoder/type.rb +5 -5
- data/lib/templates/API.erb +8 -2
- data/rpcoder.gemspec +2 -2
- data/spec/fixtures/foo/bar/API.as +25 -0
- data/spec/rpcoder_spec.rb +9 -2
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.2
|
data/lib/rpcoder/function.rb
CHANGED
|
@@ -29,6 +29,21 @@ module RPCoder
|
|
|
29
29
|
params.select { |i| !param_strs.include?(i.name.to_s) }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def set_return_type(type, options = {})
|
|
33
|
+
@return_type = type
|
|
34
|
+
@return_type_options = options
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def return_type_instance_creator(elem)
|
|
38
|
+
type = @return_type
|
|
39
|
+
type = @return_type_options[:array_type] if @return_type == 'Array'
|
|
40
|
+
if Type.original_types.include?(type)
|
|
41
|
+
elem
|
|
42
|
+
else
|
|
43
|
+
"new #{type}(#{elem})"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
32
47
|
class Param
|
|
33
48
|
attr_accessor :name, :type, :options
|
|
34
49
|
def initialize(name, type, options = {})
|
data/lib/rpcoder/type.rb
CHANGED
|
@@ -2,6 +2,10 @@ module RPCoder
|
|
|
2
2
|
class Type
|
|
3
3
|
attr_accessor :name, :description
|
|
4
4
|
|
|
5
|
+
def self.original_types
|
|
6
|
+
[:int, :String, :Boolean, :Array]
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def fields
|
|
6
10
|
@fields ||= []
|
|
7
11
|
end
|
|
@@ -19,7 +23,7 @@ module RPCoder
|
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def original_type?
|
|
22
|
-
original_types.include?(@type.to_sym)
|
|
26
|
+
Type.original_types.include?(@type.to_sym)
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
def array?
|
|
@@ -30,10 +34,6 @@ module RPCoder
|
|
|
30
34
|
Field.new(name, options[:array_type])
|
|
31
35
|
end
|
|
32
36
|
|
|
33
|
-
def original_types
|
|
34
|
-
[:int, :String, :Boolean, :Array]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
37
|
def instance_creator(elem = nil, options = {})
|
|
38
38
|
elem = name if elem.nil?
|
|
39
39
|
if original_type?
|
data/lib/templates/API.erb
CHANGED
|
@@ -105,8 +105,14 @@ package <%= name_space %>
|
|
|
105
105
|
request("<%= func.method %>", <%= func.path_parts.join(' + ') %>, params,
|
|
106
106
|
function(e:ResultEvent, t:Object):void {
|
|
107
107
|
t = t; // FIXME: for removing warning
|
|
108
|
-
<%- if func.return_type && func.return_type
|
|
109
|
-
|
|
108
|
+
<%- if func.return_type && func.return_type == 'Array' -%>
|
|
109
|
+
var hash:Object = JSON.decode(e.result as String);
|
|
110
|
+
var array:Array = new Array();
|
|
111
|
+
for (var elem:Object in hash)
|
|
112
|
+
array.push(<%= func.return_type_instance_creator('elem') %>);
|
|
113
|
+
success(array);
|
|
114
|
+
<%- elsif func.return_type != 'void' -%>
|
|
115
|
+
success(<%= func.return_type_instance_creator('JSON.decode(e.result as String)') %>);
|
|
110
116
|
<%- else -%>
|
|
111
117
|
success();
|
|
112
118
|
<%- end -%>
|
data/rpcoder.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{rpcoder}
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.2"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["jugyo", "Toshiyuki Hirooka"]
|
|
12
|
-
s.date = %q{2011-04-
|
|
12
|
+
s.date = %q{2011-04-26}
|
|
13
13
|
s.description = %q{Simple JSON HTTP RPC generator for as3}
|
|
14
14
|
s.email = %q{toshi.hirooka@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -111,6 +111,31 @@ package foo.bar
|
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* get mails
|
|
116
|
+
*
|
|
117
|
+
* @success:Function
|
|
118
|
+
* @error:Function
|
|
119
|
+
*/
|
|
120
|
+
public function getMails(success:Function, error:Function):void
|
|
121
|
+
{
|
|
122
|
+
var params:Object = {};
|
|
123
|
+
request("GET", "/mails/", params,
|
|
124
|
+
function(e:ResultEvent, t:Object):void {
|
|
125
|
+
t = t; // FIXME: for removing warning
|
|
126
|
+
var hash:Object = JSON.decode(e.result as String);
|
|
127
|
+
var array:Array = new Array();
|
|
128
|
+
for (var elem:Object in hash)
|
|
129
|
+
array.push(new Mail(elem));
|
|
130
|
+
success(array);
|
|
131
|
+
},
|
|
132
|
+
function(e:FaultEvent, t:Object):void {
|
|
133
|
+
t = t; // FIXME: for removing warning
|
|
134
|
+
error(e);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
114
139
|
public function request(method:String, path:String, params:Object, success:Function, error:Function):void
|
|
115
140
|
{
|
|
116
141
|
var service:HTTPService = createHttpService(this.baseUrl);
|
data/spec/rpcoder_spec.rb
CHANGED
|
@@ -12,20 +12,27 @@ describe "RPCoder" do
|
|
|
12
12
|
f.path = "/mails/:id" # => ("/mails/" + id)
|
|
13
13
|
f.description = 'get mail'
|
|
14
14
|
f.method = "GET"
|
|
15
|
-
f.
|
|
15
|
+
f.set_return_type "Mail"
|
|
16
16
|
f.add_param :id, :int
|
|
17
17
|
f.add_param :foo, :String, :expect => ["A","B"]
|
|
18
18
|
f.add_param :bar, :Array
|
|
19
19
|
f.add_param :baz, :Boolean, :description => "日本の文字"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
RPCoder.function "getMails" do |f|
|
|
23
|
+
f.path = "/mails/"
|
|
24
|
+
f.description = 'get mails'
|
|
25
|
+
f.method = "GET"
|
|
26
|
+
f.set_return_type "Array", {:array_type => "Mail"}
|
|
27
|
+
end
|
|
28
|
+
|
|
22
29
|
RPCoder.type "Mail" do |t|
|
|
23
30
|
t.add_field :subject, :String
|
|
24
31
|
t.add_field :body, :String
|
|
25
32
|
end
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
it { RPCoder.functions.size.should ==
|
|
35
|
+
it { RPCoder.functions.size.should == 2 }
|
|
29
36
|
|
|
30
37
|
it { RPCoder.types.size.should == 1 }
|
|
31
38
|
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: rpcoder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0.
|
|
5
|
+
version: 0.0.2
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- jugyo
|
|
@@ -11,7 +11,7 @@ autorequire:
|
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
13
|
|
|
14
|
-
date: 2011-04-
|
|
14
|
+
date: 2011-04-26 00:00:00 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: rspec
|
|
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
119
119
|
requirements:
|
|
120
120
|
- - ">="
|
|
121
121
|
- !ruby/object:Gem::Version
|
|
122
|
-
hash: -
|
|
122
|
+
hash: -3339249333839570122
|
|
123
123
|
segments:
|
|
124
124
|
- 0
|
|
125
125
|
version: "0"
|