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