require 'connection/RESTConnection.rb' require 'util/util.rb' require 'json/pure' module App42 module AppTab class SubscribeService # # this is a constructor that takes # # @param apiKey # @param secretKey # @param baseURL # def initialize(api_key, secret_key, base_url) @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "subscribe" @version = "1.0" end # # @param uName # @param schemeName # @param packageName # @param renew # @return # @throws Exception def subscribe(uName, schemeName, packageName, renew) puts "subscribe Called " puts "Base url #{@base_url}" response = nil util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(schemeName, "Name"); util.throwExceptionIfNullOrBlank(packageName, "Name"); util.throwExceptionIfNullOrBlank(renew, "Autorenew"); begin connection = App42::Connection::RESTConnection.new(@base_url) pkgObj = PackageData.new() pkgObj.store("name", packageName); schemeObj = SchemeData.new() schemeObj.store("packageDetails", pkgObj); schemeObj.store("name", schemeName); body = {'app42' => {"app"=> {"subscribe" =>{ "userName" => uName, "autoRenew" => renew, "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) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return response end # # @return # @throws Exception # def get_susbscriptions() puts "getSusbscriptions " puts "Base url #{@base_url}" response = nil 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 params.store(); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.get(signature, resource_url, query_params) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return response end # @param userName # @return # @throws Exception def get_susbscriptions_by_login(userName) puts "getSusbscriptions " puts "Base url #{@base_url}" response = nil util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); 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); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}" response = connection.get(signature, resource_url, query_params) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return response end # @param userName # @param schemeName # @param packageName # @return # @throws Exception def un_susbscriptions(userName, schemeName, packageName) puts "unSusbscriptions " puts "Base url #{@base_url}" response = nil util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(schemeName, "Name"); util.throwExceptionIfNullOrBlank(packageName, "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("userName", userName); params.store("schemeName", schemeName); params.store("packageName", packageName); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}" response = connection.get(signature, resource_url, query_params) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return response end end end end