class App42::AppTab::LicenseService
AppTab
- 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
developer can issue lincese, 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.
@see Bill
Public Class Methods
this is a constructor that takes
@param apiKey @param secretKey @param baseURL
# File lib/appTab/LicenseService.rb, line 29 def initialize(api_key, secret_key, base_url) puts "LicenseService->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "license" @version = "1.0" end
Public Instance Methods
Creates the license scheme for an app.
@param licenseName
- The name of the Scheme to be created
@param licensePrice
- Price of the Scheme to be created
@param licenseCurrency
- Currency of the Scheme to be created
@param licenseDescription
- Description of the Scheme to be created
@returns Created license Scheme
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 55 def create_license(licenseName, licensePrice, licenseCurrency, licenseDescription) puts "createLicense Called " puts "Base url #{@base_url}" response = nil; licenseObj = nil; licenseObj = License.new util = Util.new util.throwExceptionIfNullOrBlank(licenseName, "Name"); util.throwExceptionIfNullOrBlank(licensePrice, "Price"); util.throwExceptionIfNullOrBlank(licenseCurrency, "Currency"); util.throwExceptionIfNullOrBlank(licenseDescription, "Description"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"appTab"=> {"license"=>{ "name" => licenseName, "price" => licensePrice, "currency" => licenseCurrency, "description" => licenseDescription }}}}.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) license = LicenseResponseBuilder.new licenseObj = license.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseObj end
Fetches all the licenses for an App
. This can be used by app developers to display license information/pricing plan about their app to their customers.
@returns All license Schemes
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 210 def get_all_licenses() puts "get All License " puts "Base url #{@base_url}" response = nil; licenseList = nil; licenseList = Array.new util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts params puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.get(signature, resource_url, query_params) license = LicenseResponseBuilder.new licenseList = license.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseList end
Fetches all licenses issued to a particular user. This can be used by app developers to show the users their order history.
@param userName
- User Name for whom issued licenses have to be fetched
@param licenseName
- Name of the Scheme to be fetched
@returns All issued licenses
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 257 def get_issued_licenses(userName, licenseName) puts "get Issued Licenses " puts "Base url #{@base_url}" response = nil; licenseList = nil; licenseList = Array.new() util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(licenseName, "LicenseName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts params params.store("userName", userName); params.store("name", licenseName); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/#{licenseName}" response = connection.get(signature, resource_url, query_params) license = LicenseResponseBuilder.new licenseList = license.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseList end
Fetches information about the license. This can be used by an app developers to display license information/pricing plan about their app to their customers.
@param licenseName
- The name of the Scheme to be fetched
@returns Fetched license Scheme
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 166 def get_license(licenseName) puts "getLicense " puts "Base url #{@base_url}" response = nil; licenseObj = nil; licenseObj = License.new util = Util.new util.throwExceptionIfNullOrBlank(licenseName, "LicenseName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts params params.store("name", licenseName); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{licenseName}" response = connection.get(signature, resource_url, query_params) license = LicenseResponseBuilder.new licenseObj = license.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseObj end
Checks whether a particular license key is Valid or not.
@param userName
- The user for whom the validity has to be checked
@param licenseName
- The scheme name for which the validity has to be checked
@param key
- The license key which has to be validated
@returns Whether the license for the user is valid or not
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 308 def is_valid(userName, licenseName, key) puts "isValid Licenses " puts "Base url #{@base_url}" response = nil; licenseObj = nil; licenseObj = License.new util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(licenseName, "LicenseName"); util.throwExceptionIfNullOrBlank(key, "Key"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts params params.store("userName", userName); params.store("name", licenseName); params.store("key", key); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/#{licenseName}/#{key}" response = connection.get(signature, resource_url, query_params) license = LicenseResponseBuilder.new licenseObj = license.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseObj end
Issues license based on license scheme name. It returns a license key which can be used in future to fetch information about the license, or to revoke it or to find its validity.
@param userName
- The user for whom the license has to be issued
@param licenseName
- The name of the Scheme to be issued
@returns Issued license Scheme
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 113 def issue_license(userName, licenseName) puts "issueLicense Called " puts "Base url #{@base_url}" response = nil; licenseObj = nil; licenseObj = License.new util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(licenseName, "licenseName"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"appTab"=> {"license"=>{ "user" => userName, "name" => licenseName }}}}.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}/issue" response = connection.post(signature, resource_url, query_params, body) license = LicenseResponseBuilder.new licenseObj = license.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return licenseObj end
Revokes license for a particular user. Once revoked the method isValid will return that the key is inValid. Note: Once a license is revoked it cannot be made valid again.
@param userName
- The user for which the license has to be revoked
@param licenseName
- The scheme name which has to be revoked
@param key
- The license key which has to be revoked
@returns License
information which has been revoked
@throws App42Exception
# File lib/appTab/LicenseService.rb, line 362 def revoke_license(userName, licenseName, key) puts "revokeLicense Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(licenseName, "LicenseName"); util.throwExceptionIfNullOrBlank(key, "Key"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("userName", userName) params.store("name", licenseName); params.store("key", key); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/#{licenseName}/#{key}" response = connection.put(signature, resource_url, query_params, "") responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end