require 'connection/RESTConnection.rb' require 'util/util.rb' require 'json/pure' # # # AppTab API includes Bill, License and Usage explained below: # # Bill - This service is used along with the Usage service. It generates Bill # for a particular based on Usage Scheme. For e.g. if user sid's bill has to be # seen for May and 2012. This service will list all the charging transactions # and calculate the bill for May and tell the total usage and price. The # calculation is done based on the Price which is given during scheme creation, # the unit of charging and corresponding usage. AppTab currently just maintains # the data and does calculation. How the Bill is rendered and the interface # with Payment Gateway is left with the app developers. # # # Usage - Usage is part of AppTab which a rating, metering, charging and # billing engine. This service allows app developers to specify the rate for a # particular usage parameter e.g. Level - Storage - space, Bandwidth, Time, # Feature, Level of game, OneTime - Which can be used for one time charging # e.g. for charging for downloads and License for traditional license based # charging. It provides methods for first creating the scheme for charging # which specifies the unit of charging and the associated price. Subsequently a # chargeXXX call has to be made for charging. e.g. If a app developers wants to # charge on Storage. He can use the method createStorageCharge and specify that # for 10 KB/MB/GB TB the price is 10 USD Once the scheme is created. The app # developers can call the chargeStorage call whenever storage is utilized. e.g. # 5MB. Using the Bill service the app developers can find out what is the # monthly bill for a particular user based on his utilization # # # License - This service provides traditional License engine. This can be # useful to app developers who want to sell their applications on license keys # and want to use a license manager on the cloud. It allows to create a license # for a particular app. Once the license scheme is created. The app developers # can issue license, revoke license and check for validity of the license When # a license is issued a license key is generated and returned. Which is used # for revoking and checking the validity of the license. The Bill service is # used to find licenses issued to a particular user. # # module App42 module AppTab class App # # this is a constructor that takes # # @param apiKey # @param secretKey # @param baseURL # def initialize(api_key, secret_key, base_url) puts "create app->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "app" @version = "1.0" end # # Create an app for a particular organization. # # @param appName # - Name of the app that has to be created # @param orgName # - Name of the organization whose creating the app # # @returns an app created by a particular organization # # @throws Exception # def create_app(appName, orgName) puts "createApp Called " puts "Base url #{@base_url}" util = Util.new connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"app"=> { "name" => appName, "organizationName" => orgName }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts params puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.post(signature, resource_url, query_params, body) return response end end end end