Class: D2L::Valence::UserContext
- Inherits:
-
Object
- Object
- D2L::Valence::UserContext
- Defined in:
- lib/d2l/valence/user_context.rb
Overview
UserContext
Instances of this class are used to make D2L Valance API calls with the current user credentials
Instance Attribute Summary collapse
-
#app_context ⇒ Object
readonly
Returns the value of attribute app_context.
-
#server_skew ⇒ Object
in seconds.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#user_key ⇒ Object
readonly
Returns the value of attribute user_key.
Instance Method Summary collapse
-
#api_call(http_method:, route:, route_params:, query_params:) ⇒ D2L::Valence::RequestResult
Calls a API method on the Valance API.
-
#initialize(app_context:, user_id:, user_key:) ⇒ UserContext
constructor
A new instance of UserContext.
Constructor Details
#initialize(app_context:, user_id:, user_key:) ⇒ UserContext
Returns a new instance of UserContext.
15 16 17 18 19 20 |
# File 'lib/d2l/valence/user_context.rb', line 15 def initialize(app_context:, user_id:, user_key:) @app_context = app_context @user_id = user_id @user_key = user_key @server_skew = 0 end |
Instance Attribute Details
#app_context ⇒ Object (readonly)
Returns the value of attribute app_context.
6 7 8 |
# File 'lib/d2l/valence/user_context.rb', line 6 def app_context @app_context end |
#server_skew ⇒ Object
in seconds
10 11 12 |
# File 'lib/d2l/valence/user_context.rb', line 10 def server_skew @server_skew end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
6 7 8 |
# File 'lib/d2l/valence/user_context.rb', line 6 def user_id @user_id end |
#user_key ⇒ Object (readonly)
Returns the value of attribute user_key.
6 7 8 |
# File 'lib/d2l/valence/user_context.rb', line 6 def user_key @user_key end |
Instance Method Details
#api_call(http_method:, route:, route_params:, query_params:) ⇒ D2L::Valence::RequestResult
Calls a API method on the Valance API
API routes
When providing the route you can also provide the variables for the parameters in the route. For example, the following route will require β1, group_category_id: 23` for `route_params`:
/d2l/api/lp/:version/:org_unit_id/groupcategories/:group_category_id
The βto_uri` method will place the parameters in the route to make the final path. For example:
/d2l/api/lp/1.0/1/groupcategories/23
There are known parameters such as β:version` which is provided when you create your initial AppContext instance. This will mean that some routes will require no parameters for example:
/d2l/api/lp/:version/users/whoami
which becomes /d2l/api/lp/1.0/users/whoami
47 48 49 50 51 52 53 54 55 |
# File 'lib/d2l/valence/user_context.rb', line 47 def api_call(http_method:, route:, route_params:, query_params:) D2L::Valence::Request.new( user_context: self, http_method: http_method, route: route, route_params: route_params, query_params: query_params ).execute end |