Class: D2L::Valence::AppContext

Inherits:
Object
  • Object
show all
Defined in:
lib/d2l/valence/app_context.rb

Overview

AppContext

Class with contextual detail for the application (the ruby client)

Constant Summary collapse

APP_ID_PARAM =
'x_a'.freeze
AUTH_KEY_PARAM =
'x_b'.freeze
CALLBACK_URL_PARAM =
'x_target'.freeze
AUTH_SERVICE_URI_PATH =
'/d2l/auth/api/token'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(brightspace_host:, app_id:, app_key:, api_version: '1.0') ⇒ AppContext

Returns a new instance of AppContext.

Parameters:

  • brightspace_host (Valence::Host)

    Authenticating D2L Brightspace Instance

  • app_id (String)

    Application ID provided by your D2L admin

  • app_key (String)

    Application Key provided by your D2L admin

  • api_version (String) (defaults to: '1.0')

    Version of the Valence API is use



20
21
22
23
24
25
# File 'lib/d2l/valence/app_context.rb', line 20

def initialize(brightspace_host:, app_id:, app_key:, api_version: '1.0')
  @brightspace_host = brightspace_host
  @app_id = app_id
  @app_key = app_key
  @api_version = api_version
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



11
12
13
# File 'lib/d2l/valence/app_context.rb', line 11

def api_version
  @api_version
end

#app_idObject (readonly)

Returns the value of attribute app_id.



11
12
13
# File 'lib/d2l/valence/app_context.rb', line 11

def app_id
  @app_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



11
12
13
# File 'lib/d2l/valence/app_context.rb', line 11

def app_key
  @app_key
end

#brightspace_hostObject (readonly)

Returns the value of attribute brightspace_host.



11
12
13
# File 'lib/d2l/valence/app_context.rb', line 11

def brightspace_host
  @brightspace_host
end

Instance Method Details

#auth_url(callback_uri) ⇒ String

Generates a URL for authentication

Parameters:

  • callback_uri (URI::Generic)

    URI to redirect to post authentication

Returns:

  • (String)

    URL for authentication



31
32
33
34
35
36
# File 'lib/d2l/valence/app_context.rb', line 31

def auth_url(callback_uri)
  @brightspace_host.to_uri(
    path: AUTH_SERVICE_URI_PATH,
    query: query_params_using(callback_url: callback_uri.to_s)
  ).to_s
end