Sha256: 3c2a597e2d75c297c6750a9f9c05cbf8aa96f835e37e384fb5f9e362ee370eaf

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require "set"

module Atrium
  class Connect
    include ::ActiveAttr::Model

    PERMITTED_CONNECT_CREATE_OPTIONS = ::Set.new([
                                                   "current_institution_code",
                                                   "current_member_guid",
                                                   "is_mobile_webview",
                                                   "update_credentials",
                                                 ]).freeze
    SCRIPT_SOURCE = "https://atrium.mx.com/connect.js".freeze

    # ATTRIBUTES
    attribute :connect_widget_url
    attribute :guid

    ##
    # CLASS METHODS
    #
    def self.create(user_guid:, options: {})
      options.each_key do |key|
        fail ArgumentError, "An invalid option was provided: #{key}" unless PERMITTED_CONNECT_CREATE_OPTIONS.include?(key.to_s)
      end

      endpoint = "/users/#{user_guid}/connect_widget_url"
      connect_response = ::Atrium.client.make_request(:post, endpoint, options)

      connect_params = connect_response["user"]
      ::Atrium::Connect.new(connect_params)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
atrium-ruby-1.3.2 lib/atrium/connect.rb
atrium-ruby-1.3.0 lib/atrium/connect.rb