Code Monkey home page Code Monkey logo

rpcoder's Introduction

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);

rpcoder's People

Contributors

tosik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rpcoder's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.