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.
@@ -0,0 +1,39 @@
1
+ /* generated by rpcoder */
2
+
3
+ package <%= name_space %>
4
+ {
5
+ public class <%= type.name %>
6
+ {
7
+ <%- type.fields.each do |field| -%>
8
+ private var _<%= field.name %>:<%= field.type %>;
9
+ <%- end -%>
10
+
11
+ <%- type.fields.each do |field| -%>
12
+ public function get <%= field.name %>():<%= field.type %>
13
+ {
14
+ return _<%= field.name %>;
15
+ }
16
+
17
+ <%- end -%>
18
+ public function <%= type.name %>(object:Object = null)
19
+ {
20
+ if (object)
21
+ {
22
+ <%- type.fields.each do |field| -%>
23
+ <%- if field.array? -%>
24
+ _<%= field.name %> = new Array();
25
+ for each(var elem:Object in object['<%= field.name %>'])
26
+ _<%= field.name %>.push(<%= field.array_field.instance_creator(:elem, {:direct => true}) %>);
27
+ <%- else -%>
28
+ _<%= field.name %> = <%= field.instance_creator %>;
29
+ <%- end -%>
30
+ <%- end -%>
31
+ }
32
+ }
33
+
34
+ public function toString():String
35
+ {
36
+ return [<%= type.fields.map {|i| "_#{i.name}" }.join(', ') %>].join(', ');
37
+ }
38
+ }
39
+ }
data/mock/build.xml ADDED
@@ -0,0 +1,70 @@
1
+ <project name="Flex Ant Tasks Build Script" default="compile">
2
+ <!-- setup a prefix for all environment variables -->
3
+ <property environment="env" />
4
+
5
+ <!-- Setup paths for build -->
6
+ <property name="src.loc" location="${basedir}/src" />
7
+ <property name="src.test.loc" location="${basedir}/src_test" />
8
+ <property name="lib.loc" location="${basedir}/lib" />
9
+ <property name="output.loc" location="${basedir}" />
10
+ <property name="bin.loc" location="${output.loc}/bin" />
11
+ <property name="report.loc" location="${output.loc}/report" />
12
+
13
+ <!-- Setup Flex and FlexUnit ant tasks -->
14
+ <!-- You can set this directly so mxmlc will work correctly, or set FLEX_HOME as an environment variable and use as below -->
15
+ <property name="FLEX_HOME" location="${env.FLEX_HOME}" />
16
+ <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
17
+ <taskdef resource="flexUnitTasks.tasks" classpath="${lib.loc}/flexUnitTasks-4.0.0.jar" />
18
+
19
+ <target name="init">
20
+ <!-- Create directories needed for the build process -->
21
+ <mkdir dir="${bin.loc}" />
22
+ <mkdir dir="${report.loc}" />
23
+ </target>
24
+
25
+ <target name="mock_rpcoder">
26
+ <exec executable="ruby">
27
+ <arg line="mock_rpcoder.rb"/>
28
+ </exec>
29
+ </target>
30
+
31
+ <!-- Build and output the Main.swf-->
32
+ <target name="compile" depends="init,mock_rpcoder">
33
+ <mxmlc file="${src.loc}/Mock.mxml" output="${bin.loc}/Mock.swf">
34
+ <source-path path-element="${FLEX_HOME}/frameworks"/>
35
+ <library-path dir="${lib.loc}" append="true">
36
+ <include name="*.swc" />
37
+ </library-path>
38
+ <compiler.debug>false</compiler.debug>
39
+ </mxmlc>
40
+ </target>
41
+
42
+ <target name="compile_test_runner" depends="init,mock_rpcoder">
43
+ <mxmlc file="${src.test.loc}/FlexUnitRunner.mxml" output="${bin.loc}/FlexUnitRunner.swf">
44
+ <source-path path-element="${src.loc}" />
45
+ <source-path path-element="${src.test.loc}" />
46
+ <library-path dir="${lib.loc}" append="true">
47
+ <include name="*.swc" />
48
+ </library-path>
49
+ <compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
50
+ <compiler.headless-server>true</compiler.headless-server>
51
+ </mxmlc>
52
+ </target>
53
+
54
+ <target name="test" depends="compile_test_runner">
55
+ <!-- Execute FlexUnit tests and publish reports -->
56
+ <flexunit swf="${bin.loc}/FlexUnitRunner.swf"
57
+ toDir="${report.loc}"
58
+ haltonfailure="false"
59
+ verbose="true"
60
+ headless="true"
61
+ localTrusted="true" />
62
+ <!-- Generate readable JUnit-style reports -->
63
+ <junitreport todir="${report.loc}">
64
+ <fileset dir="${report.loc}">
65
+ <include name="TEST-*.xml" />
66
+ </fileset>
67
+ <report format="frames" todir="${report.loc}/html" />
68
+ </junitreport>
69
+ </target>
70
+ </project>
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
5
+ require 'rpcoder'
6
+ require 'fileutils'
7
+
8
+ #######################################
9
+ # API definition
10
+ #######################################
11
+
12
+ RPCoder.name_space = 'com.oneup.rpcoder.mock'
13
+ RPCoder.api_class_name = 'API'
14
+
15
+ RPCoder.type "Mail" do |t|
16
+ t.add_field :subject, :String
17
+ t.add_field :body, :String
18
+ end
19
+
20
+ RPCoder.function "getMail" do |f|
21
+ f.path = "/mails/:id" # => ("/mails/" + id)
22
+ f.method = "GET"
23
+ f.return_type = "Mail"
24
+ f.add_param :id, "int"
25
+ f.description = 'メールを取得'
26
+ end
27
+
28
+ RPCoder.function "sendMail" do |f|
29
+ f.path = "/mails" # => ("/mails/" + id)
30
+ f.method = "POST"
31
+ f.return_type = "void"
32
+ f.add_param :subject, "String"
33
+ f.add_param :body, "String"
34
+ f.description = 'メールを送信'
35
+ end
36
+
37
+ RPCoder.function "getError" do |f|
38
+ f.path = "/error/:statusCode"
39
+ f.method = "GET"
40
+ f.return_type = "void"
41
+ f.add_param :statusCode, :int
42
+ f.description = 'Get Error'
43
+ end
44
+
45
+ dir = File.expand_path('src', File.dirname(__FILE__))
46
+ RPCoder.export(dir)
@@ -0,0 +1,34 @@
1
+ #
2
+ # == Usage
3
+ #
4
+ # $ ruby mock_server.rb
5
+ #
6
+
7
+ require 'sinatra'
8
+ require 'json'
9
+
10
+ get '/crossdomain.xml' do
11
+ <<XML
12
+ <?xml version="1.0"?>
13
+ <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
14
+ <cross-domain-policy>
15
+ <allow-access-from domain="*" />
16
+ </cross-domain-policy>
17
+ XML
18
+ end
19
+
20
+ get '/mails/:id' do
21
+ puts "url: #{request.url}"
22
+ puts "params: #{params.inspect}"
23
+ {"id" => params[:id], "subject" => "hi", "body" => "hi, I'm ..."}.to_json
24
+ end
25
+
26
+ post '/mails' do
27
+ puts "url: #{request.url}"
28
+ puts "params: #{params.inspect}"
29
+ {}.to_json
30
+ end
31
+
32
+ get '/error/:status_code' do
33
+ halt params[:status_code].to_i, "Error[#{params[:status_code]}]"
34
+ end
@@ -0,0 +1,62 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
3
+ xmlns:s="library://ns.adobe.com/flex/spark"
4
+ xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
5
+
6
+ <fx:Script>
7
+ <![CDATA[
8
+ import com.oneup.rpcoder.mock.API
9
+ import com.oneup.rpcoder.mock.Mail
10
+ import mx.rpc.events.FaultEvent;
11
+
12
+ protected function button1_clickHandler(event:MouseEvent):void
13
+ {
14
+ var api:API = new API("http://localhost:4567/");
15
+ api.getMail(
16
+ 1,
17
+ function(result:Mail):void {
18
+ outputText.text += "getMail => " + result.toString() + "\n";
19
+ },
20
+ function(e:FaultEvent):void {
21
+ outputText.text += e.statusCode + ": " + e.fault.content + "\n"
22
+ }
23
+ );
24
+ }
25
+
26
+ protected function button2_clickHandler(event:MouseEvent):void
27
+ {
28
+ var api:API = new API("http://localhost:4567/");
29
+ api.sendMail('hello', 'hello, I\'m foo',
30
+ function():void {
31
+ outputText.text += "mail has been sent\n"
32
+ },
33
+ function(e:FaultEvent):void {
34
+ outputText.text += e.statusCode + ": " + e.fault.content + "\n"
35
+ }
36
+ );
37
+ }
38
+
39
+ protected function button3_clickHandler(event:MouseEvent):void
40
+ {
41
+ var api:API = new API("http://localhost:4567/");
42
+ api.errorHandler = function(e:FaultEvent, t:Object):void {
43
+ outputText.text += e.statusCode + ": " + e.fault.content + "\n"
44
+ }
45
+ api.getError(
46
+ 500,
47
+ function():void {},
48
+ function(e:FaultEvent):void {}
49
+ );
50
+ }
51
+ ]]>
52
+ </fx:Script>
53
+
54
+ <fx:Declarations>
55
+ <!-- Place non-visual elements (e.g., services, value objects) here -->
56
+ </fx:Declarations>
57
+
58
+ <s:Button x="10" y="10" label="getMail" click="button1_clickHandler(event)"/>
59
+ <s:Button x="100" y="10" label="sendMail" click="button2_clickHandler(event)"/>
60
+ <s:Button x="200" y="10" label="getError" click="button3_clickHandler(event)"/>
61
+ <s:TextArea x="10" y="39" width="300" height="300" editable="false" id="outputText"/>
62
+ </s:Application>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <s:Application
3
+ xmlns:fx="http://ns.adobe.com/mxml/2009"
4
+ xmlns:s="library://ns.adobe.com/flex/spark"
5
+ xmlns:mx="library://ns.adobe.com/flex/mx"
6
+ xmlns:adobe="http://www.adobe.com/2009/flexUnitUIRunner"
7
+ creationComplete="runMe()">
8
+
9
+ <fx:Script>
10
+ <![CDATA[
11
+ import org.flexunit.listeners.CIListener;
12
+ import org.flexunit.listeners.UIListener;
13
+ import org.flexunit.runner.FlexUnitCore;
14
+
15
+ private var core:FlexUnitCore;
16
+
17
+ public function runMe():void {
18
+ core = new FlexUnitCore();
19
+ core.addListener(new UIListener(uiListener));
20
+ core.addListener(new CIListener());
21
+ core.run(TestSuite);
22
+ }
23
+ ]]>
24
+ </fx:Script>
25
+
26
+ <adobe:TestRunnerBase id="uiListener" width="100%" height="100%" />
27
+ </s:Application>
@@ -0,0 +1,10 @@
1
+ package {
2
+ import com.oneup.rpcoder.test.APITest;
3
+ import com.oneup.rpcoder.test.TypeTest;
4
+ [Suite]
5
+ [RunWith("org.flexunit.runners.Suite")]
6
+ public class TestSuite {
7
+ public var t1:APITest;
8
+ public var t2:TypeTest;
9
+ }
10
+ }
@@ -0,0 +1,76 @@
1
+ package com.oneup.rpcoder.test {
2
+ import mx.rpc.AsyncToken;
3
+ import mx.rpc.http.HTTPService;
4
+ import flash.events.*;
5
+ import mockolate.*;
6
+ import mx.rpc.events.FaultEvent;
7
+ import org.flexunit.asserts.*;
8
+ import org.flexunit.async.Async;
9
+ import org.hamcrest.core.anything;
10
+
11
+ import com.oneup.rpcoder.mock.*;
12
+
13
+ public class APITest {
14
+ /*
15
+ * Preparing
16
+ */
17
+ [Before(async, timeout=5000)]
18
+ public function prepareMockolates() : void {
19
+ Async.proceedOnEvent(this, prepare(API, HTTPService, AsyncToken), Event.COMPLETE);
20
+ }
21
+
22
+ [Test(description="API を new できる")]
23
+ public function newAPI() : void {
24
+ var api : API = new API('http://example.com/');
25
+ assertEquals('http://example.com/', api.baseUrl);
26
+ }
27
+
28
+ [Test(description="API#getMail を呼び出せる")]
29
+ public function callGetMail() : void {
30
+ var api : API = nice(API);
31
+ mock(api).method("request").args('GET', '/mails/1', anything(), anything(), anything());
32
+ stub(api).method("getMail").callsSuper();
33
+ api.getMail(
34
+ 1,
35
+ function(mail : Mail) : void {},
36
+ function(e : FaultEvent) : void {}
37
+ );
38
+ verify(api);
39
+ }
40
+
41
+ [Test(description="API#sendMail を呼び出せる")]
42
+ public function callSendMail() : void {
43
+ var api : API = nice(API);
44
+ mock(api).method("request").args('POST', '/mails', anything(), anything(), anything());
45
+ stub(api).method("sendMail").callsSuper();
46
+ api.sendMail(
47
+ 'hi',
48
+ 'foo bar',
49
+ function(mail : Mail) : void {},
50
+ function(e : FaultEvent) : void {}
51
+ );
52
+ verify(api);
53
+ }
54
+
55
+ [Test(description="API#request を呼び出せる")]
56
+ public function callRequest() : void {
57
+ var api : API = nice(API);
58
+ var service : HTTPService = strict(HTTPService);
59
+ var token : AsyncToken = strict(AsyncToken);
60
+ var params : Object = {foo:'foo', bar:'bar'};
61
+
62
+ stub(api).method("createHttpService").anyArgs().returns(service);
63
+ mock(service).setter("method").arg("GET");
64
+ mock(service).setter("url").arg('/foo');
65
+ mock(service).setter("request").arg(params);
66
+ mock(service).setter("resultFormat").arg("text");
67
+ mock(service).method("send").returns(token);
68
+ mock(token).method("addResponder").anyArgs();
69
+
70
+ stub(api).method("request").callsSuper();
71
+ api.request('GET', '/foo', params, function():void{}, function():void{});
72
+
73
+ verify(service);
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,25 @@
1
+ package com.oneup.rpcoder.test {
2
+ import org.flexunit.asserts.assertEquals;
3
+ import com.oneup.rpcoder.mock.*;
4
+
5
+ public class TypeTest
6
+ {
7
+ [Test(description="オブジェクトを作成できる")]
8
+ public function createObject():void
9
+ {
10
+ var data:Object = {subject:'hi', body: 'foo bar'};
11
+ var mail:Mail = new Mail(data);
12
+ assertEquals(data['subject'], mail.subject);
13
+ assertEquals(data['body'], mail.body);
14
+ }
15
+
16
+ [Test(description="少ないデータをもとにオブジェクトを作成できる")]
17
+ public function createObjectWithFewData():void
18
+ {
19
+ var data:Object = {subject:'hi'};
20
+ var mail:Mail = new Mail(data);
21
+ assertEquals(data['subject'], mail.subject);
22
+ assertEquals(null, mail.body);
23
+ }
24
+ }
25
+ }
data/rpcoder.gemspec ADDED
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rpcoder}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jugyo", "Toshiyuki Hirooka"]
12
+ s.date = %q{2011-04-25}
13
+ s.description = %q{Simple RPC generator for as3}
14
+ s.email = %q{toshi.hirooka@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rpcoder.rb",
27
+ "lib/rpcoder/function.rb",
28
+ "lib/rpcoder/type.rb",
29
+ "lib/templates/API.erb",
30
+ "lib/templates/Type.erb",
31
+ "mock/build.xml",
32
+ "mock/lib/as3corelib.swc",
33
+ "mock/lib/flexUnitTasks-4.0.0.jar",
34
+ "mock/lib/flexunit-4.0.0.swc",
35
+ "mock/lib/flexunit-cilistener-4.0.0.swc",
36
+ "mock/lib/flexunit-flexcoverlistener-4.0.0.swc",
37
+ "mock/lib/flexunit-uilistener-4.0.0.swc",
38
+ "mock/lib/hamcrest-as3-1.1.1.swc",
39
+ "mock/lib/mockolate-0.9.3.swc",
40
+ "mock/mock_rpcoder.rb",
41
+ "mock/mock_server.rb",
42
+ "mock/src/Mock.mxml",
43
+ "mock/src_test/FlexUnitRunner.mxml",
44
+ "mock/src_test/TestSuite.as",
45
+ "mock/src_test/com/oneup/rpcoder/test/APITest.as",
46
+ "mock/src_test/com/oneup/rpcoder/test/TypeTest.as",
47
+ "rpcoder.gemspec",
48
+ "spec/fixtures/foo/bar/API.as",
49
+ "spec/fixtures/foo/bar/Mail.as",
50
+ "spec/rpcoder/function_spec.rb",
51
+ "spec/rpcoder_spec.rb",
52
+ "spec/spec_helper.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/one-up/rpcoder}
55
+ s.licenses = ["MIT"]
56
+ s.require_paths = ["lib"]
57
+ s.rubygems_version = %q{1.7.2}
58
+ s.summary = %q{Simple RPC generator for as3}
59
+ s.test_files = [
60
+ "spec/rpcoder/function_spec.rb",
61
+ "spec/rpcoder_spec.rb",
62
+ "spec/spec_helper.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
69
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
70
+ s.add_development_dependency(%q<rspec>, [">= 0"])
71
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_development_dependency(%q<rcov>, [">= 0"])
74
+ s.add_development_dependency(%q<rake>, [">= 0"])
75
+ else
76
+ s.add_dependency(%q<sinatra>, [">= 0"])
77
+ s.add_dependency(%q<rspec>, [">= 0"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
80
+ s.add_dependency(%q<rcov>, [">= 0"])
81
+ s.add_dependency(%q<rake>, [">= 0"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<sinatra>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
88
+ s.add_dependency(%q<rcov>, [">= 0"])
89
+ s.add_dependency(%q<rake>, [">= 0"])
90
+ end
91
+ end
92
+