Project

rpcoder

0.01
No commit activity in last 3 years
No release in over 3 years
Simple JSON HTTP RPC generator for as3
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0.0
~> 1.5.2
>= 0
>= 0
>= 0
 Project Readme

rpcoder¶ ↑

installation¶ ↑

$ gem install rpcoder

ruby code for AS3 RPC¶ ↑

#!/usr/bin/env ruby

require 'rpcoder'
require 'fileutils'

RPCoder.name_space = 'foo.bar.rpc'
RPCoder.api_class_name = 'RPC'

RPCoder.type "Mail" do |t|
  t.add_field :subject, :String
  t.add_field :body,    :String
end

RPCoder.function "getMail" do |f|
  f.path        = "/mails/:id" # => ("/mails/" + id)
  f.method      = "GET"
  f.add_return_type :mail, "Mail"
  f.add_param  :id, "int"
  f.description = 'メールを取得'
end

RPCoder.function "getMails" do |f|
  f.path        = "/mails"
  f.method      = "GET"
  f.add_return_type :mails, "Mail", {:array? => true}
  f.description = 'メールを送信'
end

RPCoder.function "sendMail" do |f|
  f.path        = "/mails/create"
  f.method      = "POST"
  f.add_param  :subject, "String"
  f.add_param  :body,    "String"
  f.description = 'メールを送信'
end

# output codes
dir = File.expand_path('src', File.dirname(__FILE__))
RPCoder.export(dir)

as3 code for using RPC¶ ↑

var rpc:RPC = new RPC('http://localhost:3000');

rpc.getMail(1, function(mail:Mail):void {
	// success
}, function():void {
	// failure
})

rpc.getMails(function(mails:Array):void {
	// success

for each (var mail as Mail in mails) { }

}, function():void {
	// failure
})

dummy RPC¶ ↑

Dummy RPC works standalone. You can set anything responses at callback.

var rpc:RPCInterface = new RPCDummy();
(rpc as RPCDummy).setDummySuccess("getMail", [
    Mail.create('foo', 'bar')
]);

rpc.getMail(function(mail:Mail):void {
    // success
    // responded mail as dummy
}, function():void {
    // error
});

// rpc.getMail() may callback as error.
(rpc as RPCDummy).setDummyError("getMail", true);