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.19.28 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.27 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.26 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.25 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.24 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.23 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.22 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.21 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.20 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.19 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.18 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.17 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.16 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.15 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.14 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.13 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.12 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.11 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.19.10 lib/platform_sdk/learnosity_api/client.rb
strongmind-platform-sdk-3.14.2 lib/platform_sdk/learnosity_api/client.rb