# frozen_string_literal: true require 'rest-client' require 'active_support/core_ext/hash' module Wso2Toolbox module TokenManager module ApiManagerService class << self def create_token post(config.token_url, build_params) end def refresh_token(token) post(config.refresh_token_url, token: token) end def revoke_token(token) post(config.revoke_token_url, token: token) end private_class_method def config @config ||= Wso2Toolbox.configuration end def build_params { user_name: config.token_username, password: config.token_password } end def post(url, params) response = RestClient.post(url, params.to_json, content_type: :json) JSON.parse(response).with_indifferent_access end end end end end