Sha256: 6926d61e82d6a08999d4e0dafa4f57e80626875dc3f3c444d2c92a30ad1c0c3a

Contents?: true

Size: 1.62 KB

Versions: 55

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true
require "learnosity/sdk/request/init"
require "securerandom"
require "net/http"

module PlatformSdk
  module LearnosityApi
    # Learnosity::Client
    class Client
      attr_reader :credentials, :security

      def initialize(credentials)
        @credentials = credentials

        raise ArgumentError, "learnosity_host is required" if @credentials[:learnosity_host].nil?
        raise ArgumentError, "learnosity_version is required" if @credentials[:learnosity_version].nil?
        raise ArgumentError, "service is required" if @credentials[:service].nil?
        raise ArgumentError, "consumer_key is required" if @credentials[:consumer_key].nil?
        raise ArgumentError, "consumer_secret is required" if @credentials[:consumer_secret].nil?
        raise ArgumentError, "organisation_id is required" if @credentials[:organisation_id].nil?
        raise ArgumentError, "domain is required" if @credentials[:domain].nil?

        @security = {
          "consumer_key" => @credentials[:consumer_key],
          "user_id" => SecureRandom.uuid,
          "domain" => @credentials[:domain]
        }

      end

      def sign(request)
        init = Learnosity::Sdk::Request::Init.new(
          @credentials[:service],
          @security,
          @credentials[:consumer_secret],
          request
        )
        init.generate
      end

      def post(path, request)
        request["organisation_id"] = @credentials[:organisation_id]
        uri = URI("https://#{@credentials[:learnosity_host]}/#{@credentials[:learnosity_version]}/#{path}")
        Net::HTTP.post_form(uri, sign(request))
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
strongmind-platform-sdk-3.21.3 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.21.2 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.21.1 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.21.0 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.20.3 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.20.2 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.20.1 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.20.0 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.40 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.39 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.38 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.37 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.36 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.35 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.34 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.33 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.32 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.31 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.30 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.29 lib/platform_sdk/learnosity_api/client.rb