Class: App42::AppTab::LicenseService
- Inherits:
-
Object
- Object
- App42::AppTab::LicenseService
- Defined in:
- lib/appTab/LicenseService.rb
Overview
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
Instance Method Summary collapse
-
#create_license(licenseName, licensePrice, licenseCurrency, licenseDescription) ⇒ Object
Creates the license scheme for an app.
-
#get_all_licenses ⇒ Object
Fetches all the licenses for an App.
-
#get_issued_licenses(userName, licenseName) ⇒ Object
Fetches all licenses issued to a particular user.
-
#get_license(licenseName) ⇒ Object
Fetches information about the license.
-
#initialize(api_key, secret_key, base_url) ⇒ LicenseService
constructor
this is a constructor that takes.
-
#is_valid(userName, licenseName, key) ⇒ Object
Checks whether a particular license key is Valid or not.
-
#issue_license(userName, licenseName) ⇒ Object
Issues license based on license scheme name.
-
#revoke_license(userName, licenseName, key) ⇒ Object
Revokes license for a particular user.
Constructor Details
#initialize(api_key, secret_key, base_url) ⇒ LicenseService
this is a constructor that takes
29 30 31 32 33 34 35 36 |
# 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 |
Instance Method Details
#create_license(licenseName, licensePrice, licenseCurrency, licenseDescription) ⇒ Object
Creates the license scheme for an app.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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., } 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 |
#get_all_licenses ⇒ Object
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.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# 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., } 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 |
#get_issued_licenses(userName, licenseName) ⇒ Object
Fetches all licenses issued to a particular user. This can be used by app developers to show the users their order history.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# 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., } 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 |
#get_license(licenseName) ⇒ Object
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.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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., } 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 |
#is_valid(userName, licenseName, key) ⇒ Object
Checks whether a particular license key is Valid or not.
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# 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., } 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 |
#issue_license(userName, licenseName) ⇒ Object
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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# 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., } 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 |
#revoke_license(userName, licenseName, key) ⇒ Object
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.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# 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., } 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 |