require 'connection/RESTConnection.rb' require 'util/util.rb' require 'json/pure' require 'rubygems' require 'App42Response.rb' require 'appTab/SchemeData.rb' require 'appTab/SchemeResponseBuilder.rb' module App42 module AppTab class SchemeService # # this is a constructor that takes # # @param apiKey # @param secretKey # @param baseURL # def initialize(api_key, secret_key, base_url) puts "LicenseService->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "scheme" @version = "1.0" end # # @param aName # @param schemeName # @param desc # @return # @throws Exception # def create_scheme(schemeName, description) puts "createScheme Called " puts "Base url #{@base_url}" response = nil; schemeDataObj = nil; schemeDataObj = SchemeData.new() util = Util.new util.throwExceptionIfNullOrBlank(schemeName, "Name"); util.throwExceptionIfNullOrBlank(description, "Description"); begin connection = App42::Connection::RESTConnection.new(@base_url) schemeObj = Hash.new() schemeObj.store("name", schemeName); schemeObj.store("description", description); body = {'app42' => {"app" => { "scheme" => schemeObj }}}.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) scheme = SchemeResponseBuilder.new schemeDataObj = scheme.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return schemeDataObj end # #@return # def get_schemes() puts "getSchemes called" puts "Base url #{@base_url}" response = nil; schemeDataList = nil; schemeDataList = 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) scheme = SchemeResponseBuilder.new schemeDataList = scheme.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return schemeDataList end # # @param schemeName # @return # def get_scheme_by_name(schemeName) puts "getSchemeByName " puts "Base url #{@base_url}" response = nil; schemeDataObj = nil; schemeDataObj = SchemeData.new() util = Util.new util.throwExceptionIfNullOrBlank(schemeName, "Name"); 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("schemeName", schemeName); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{schemeName}" response = connection.get(signature, resource_url, query_params) scheme = SchemeResponseBuilder.new schemeDataObj = scheme.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return schemeDataObj end end end end