Sha256: de10ea5cd6725a33bc56ab5eb326c1cbafdda3c63d0704c6f5b302859c1de607

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wso2_toolbox-0.3.0 lib/wso2_toolbox/token_manager/api_manager_service.rb