Module: Conversant::V3::Mixins::Authentication

Defined in:
lib/conversant/v3/mixins/authentication.rb

Overview

Authentication mixin for integrating V3 authentication into existing classes

This mixin provides a bridge for existing classes to use Conversant V3 authentication without fully adopting the gem's service architecture. It's designed for gradual migration and backward compatibility.

Examples:

Basic usage in existing class

class MyExistingClass
  include Conversant::V3::Mixins::Authentication
  use_conversant_auth!

  def initialize(customer_id, type = 2)
    initialize_conversant_auth(customer_id, type)
  end

  def my_cdn_call
    headers = cdn_authorized_headers
    # Make API call with headers
  end
end

Drop-in replacement for ConversantHttpClientV3

module ConversantHttpClientV3
  def self.included(base)
    base.class_eval do
      include Conversant::V3::Mixins::Authentication
      use_conversant_auth!
    end
  end

  def authenticate
    conversant_authenticate
  end
end

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#customer_idInteger (readonly)

Returns Customer ID for API calls.

Returns:

  • (Integer)

    Customer ID for API calls

Since:

  • 1.0.0



72
73
74
# File 'lib/conversant/v3/mixins/authentication.rb', line 72

def customer_id
  @customer_id
end

#typeInteger (readonly)

Returns Customer type.

Returns:

  • (Integer)

    Customer type

Since:

  • 1.0.0



75
76
77
# File 'lib/conversant/v3/mixins/authentication.rb', line 75

def type
  @type
end

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Hook called when module is included

Parameters:

  • base (Class)

    The class including this module

Since:

  • 1.0.0



47
48
49
# File 'lib/conversant/v3/mixins/authentication.rb', line 47

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#cdn_authorized_headersHash{String => String}

Returns authorized headers for CDN API calls

Delegates to CDN service class which uses the Authorization module.

Examples:

headers = cdn_authorized_headers
response = RestClient.get(cdn_url, headers)

Returns:

  • (Hash{String => String})

    Headers hash with 'Cookie' header containing SESSION and SSO_GW_SESSION2

Since:

  • 1.0.0



141
142
143
# File 'lib/conversant/v3/mixins/authentication.rb', line 141

def cdn_authorized_headers
  cdn_service.send(:authorized_headers)
end

#conversant_authenticateHash{Symbol => String}?

Authenticates and returns SSO sessions

Wrapper method for backward compatibility with existing code.

Examples:

sessions = conversant_authenticate
if sessions
  puts sessions[:session]
end

Returns:

  • (Hash{Symbol => String}, nil)

    Hash with :session and :sso_gw_session2 keys, or nil on failure

Since:

  • 1.0.0



109
110
111
# File 'lib/conversant/v3/mixins/authentication.rb', line 109

def conversant_authenticate
  authenticate
end

#initialize_conversant_auth(customer_id, type = 2) ⇒ void

This method returns an undefined value.

Initializes authentication with customer ID and type

Call this from your class's initialize method to set up authentication.

Examples:

def initialize(customer_id, type = 2)
  initialize_conversant_auth(customer_id, type)
end

Parameters:

  • customer_id (Integer)

    Customer ID for API calls

  • type (Integer) (defaults to: 2)

    Customer type (default: 2)

Since:

  • 1.0.0



91
92
93
94
# File 'lib/conversant/v3/mixins/authentication.rb', line 91

def initialize_conversant_auth(customer_id, type = 2)
  @customer_id = customer_id # @type [Integer]
  @type = type # @type [Integer]
end

#lms_authorized_headersHash{String => String}

Returns authorized headers for LMS API calls

Delegates to LMS service class which uses the Authorization module.

Examples:

headers = lms_authorized_headers
response = RestClient.get(lms_url, headers)

Returns:

  • (Hash{String => String})

    Headers hash with 'Cookie' header containing JSESSIONID and SSO_GW_SESSION2

Since:

  • 1.0.0



156
157
158
# File 'lib/conversant/v3/mixins/authentication.rb', line 156

def lms_authorized_headers
  lms_service.send(:authorized_headers)
end

#portal_authorized_headersHash{String => String}

Returns authorized headers for Portal API calls

Delegates to Portal service class which uses the Authorization module.

Examples:

headers = portal_authorized_headers
response = RestClient.get(url, headers)

Returns:

  • (Hash{String => String})

    Headers hash with 'Cookie' header containing SESSION and SSO_GW_SESSION2

Raises:

Since:

  • 1.0.0



126
127
128
# File 'lib/conversant/v3/mixins/authentication.rb', line 126

def portal_authorized_headers
  portal_service.send(:authorized_headers)
end

#vms_authorized_headersHash{String => String}

Returns authorized headers for VMS API calls

Delegates to VMS service class which uses the Authorization module.

Examples:

headers = vms_authorized_headers
response = RestClient.get(vms_url, headers)

Returns:

  • (Hash{String => String})

    Headers hash with 'Cookie' header containing JSESSIONID and SSO_GW_SESSION2

Since:

  • 1.0.0



171
172
173
# File 'lib/conversant/v3/mixins/authentication.rb', line 171

def vms_authorized_headers
  vms_service.send(:authorized_headers)
end