Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions as3test/contract.rb

This file was deleted.

File renamed without changes.
43 changes: 43 additions & 0 deletions as3test/rpcoder_exporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module RPCoder
class << self
def export()
class_dir = dir_to_export_classes(@output_path)
FileUtils.mkdir_p(class_dir)

[
{:path => File.join(class_dir, api_class_name.split('.').last + "Interface.as"), :content => render_functions_interface},
{:path => File.join(class_dir, api_class_name.split('.').last + ".as"), :content => render_functions},
{:path => File.join(class_dir, api_class_name.split('.').last + "Dummy.as"), :content => render_functions_dummy},
].each do |hash|
puts "API: #{hash[:path]}"
File.open(hash[:path], "w") { |file| file << hash[:content] }
end
types.each { |type| export_type(type, File.join(class_dir, "#{type.name}.as")) }
end

def render_functions_interface
render_erb(template_path('APIInterface'), binding)
end

def render_functions
render_erb(template_path('API'), binding)
end

def render_functions_dummy
render_erb(template_path('APIDummy'), binding)
end

def export_type(type, path)
puts "Type: #{path}"
File.open(path, "w") { |file| file << render_type(type) }
end

def render_type(type)
render_erb(template_path('Type'), binding)
end

def dir_to_export_classes(dir)
File.join(dir, *name_space.split('.'))
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env ruby
# encoding: utf-8

abort 'environment parameter "PL" required' unless ENV['PL']
lang_path = ':LANG'.sub(':LANG',ENV['PL'])
$LOAD_PATH.unshift(File.expand_path(lang_path, File.dirname(__FILE__)))

$LOAD_PATH.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
require 'rpcoder'
require 'fileutils'

#######################################
# API definition
#######################################

RPCoder.output_path = File.expand_path("#{lang_path}/src", File.dirname(__FILE__))
RPCoder.templates_path = lang_path, 'templates'
RPCoder.name_space = 'com.aiming.rpcoder.generated'
RPCoder.api_class_name = 'API'

# Constants ------------------------------------------------------------------------------------------------------------
# コントラクトバージョンのパラメータ名
CONTRACT_VERSION_VARIABLE_NAME = 'contract_version'

# ユーザ登録
CONTRACT_USER_NAME_LENGTH_MAX = 16 # 登録名の最大長 (半角16,全角8文字)

# 生産兵数
CONTRACT_TRAIN_TROOP_COUNT_MAX = 9999 # 最大数
CONTRACT_TRAIN_TROOP_COUNT_MIN = 1 # 最小数

# マップ
CONTRACT_MAP_MAX = 500 # 最大サイズ
CONTRACT_MAP_MIN = -500 # 最小サイズ

# マップブックマーク
CONTRACT_BOOKMARK_MAP_NAME_LENGTH_MAX = 14 # 登録名の最大長


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

# Functions ------------------------------------------------------------------------------------------------------------
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 "sendMail" do |f|
f.path = "/mails" # => ("/mails/" + id)
f.method = "POST"
f.add_param :subject, "String"
f.add_param :body, "String"
f.description = 'メールを送信'
end

RPCoder.function "getError" do |f|
f.path = "/error/:statusCode"
f.method = "GET"
f.add_param :statusCode, :int
f.description = 'Get Error'
end

RPCoder.export()
70 changes: 70 additions & 0 deletions contract_php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env ruby
# encoding: utf-8

abort 'environment parameter "PL" required' unless ENV['PL']
lang_path = ':LANG'.sub(':LANG',ENV['PL'])
$LOAD_PATH.unshift(File.expand_path(lang_path, File.dirname(__FILE__)))

$LOAD_PATH.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
require 'rpcoder'
require 'fileutils'

#######################################
# API definition
#######################################

RPCoder.output_path = File.expand_path("#{lang_path}/src", File.dirname(__FILE__))
RPCoder.templates_path = lang_path, 'templates'
RPCoder.name_space = 'com.aiming.rpcoder.generated'
RPCoder.api_class_name = 'API'

# Constants ------------------------------------------------------------------------------------------------------------
# コントラクトバージョンのパラメータ名
CONTRACT_VERSION_VARIABLE_NAME = 'contract_version'

# ユーザ登録
CONTRACT_USER_NAME_LENGTH_MAX = 16 # 登録名の最大長 (半角16,全角8文字)

# 生産兵数
CONTRACT_TRAIN_TROOP_COUNT_MAX = 9999 # 最大数
CONTRACT_TRAIN_TROOP_COUNT_MIN = 1 # 最小数

# マップ
CONTRACT_MAP_MAX = 500 # 最大サイズ
CONTRACT_MAP_MIN = -500 # 最小サイズ

# マップブックマーク
CONTRACT_BOOKMARK_MAP_NAME_LENGTH_MAX = 14 # 登録名の最大長


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

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

RPCoder.function "sendMail" do |f|
f.path = "/sendmails.php" # => ("/mails/" + id)
f.method = "POST"
f.add_param :subject, "String"
f.add_param :body, "String"
f.description = 'メールを送信'
end

RPCoder.function "getError" do |f|
f.path = "/error.php"
f.method = "GET"
f.add_param :statusCode, :int
f.description = 'Get Error'
end

RPCoder.export()
129 changes: 129 additions & 0 deletions csharptest/param.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
require 'camelizer'

module RPCoder
class Param
def self.original_types
[:int, :Int, :double, :Double, :string, :String, :bool, :Boolean, :Array]
end

attr_accessor :name, :type, :options
def initialize(name, type, options = {})
@name = name
@type = type
@options = options
end

def array?
options[:array?]
end

def optional?
options[:require] == false
end

def array_or_type
if array?
"List<#{to_c_sharp_type}>"
else
to_c_sharp_type
end
end

def to_c_sharp_type
case type.to_sym
when :int
if self.optional?
return :int?
else
return :int
end
when :Int
if self.optional?
return :int?
else
return :int
end
when :double
if self.optional?
return :double?
else
return :double
end
when :Double
if self.optional?
return :double?
else
return :double
end
when :string
return :string
when :String
return :string
when :bool
if self.optional?
return :bool?
else
return :bool
end
when :Boolean
if self.optional?
return :bool?
else
return :bool
end
else
return type
end
end

def to_json_type?
case type.to_sym
when :int
return "IsInt"
when :Int
return "IsInt"
when :double
return "IsDouble"
when :Double
return "IsDouble"
when :string
return "IsString"
when :String
return "IsString"
when :bool
return "IsBoolean"
when :Boolean
return "IsBoolean"
else
return type
end
end

def original_type?
Param.original_types.include?(type.to_sym)
end

def double?
self.to_json_type? == "IsDouble"
end

def instance_creator(elem = 'elem', options = {})
elem = element_accessor(elem, options)
if original_type?
elem
else
"new #{type}(#{elem})"
end
end

def element_accessor(elem = 'elem', options = {})
if options[:object?]
"object['#{elem}']"
else
elem
end
end

end
end

Loading