Class: D2L::Valence::Request
- Inherits:
-
Object
- Object
- D2L::Valence::Request
- Defined in:
- lib/d2l/valence/request.rb
Overview
Request
Class for authenticated calls to the D2L Valence API
Instance Attribute Summary collapse
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#user_context ⇒ Object
readonly
Returns the value of attribute user_context.
Instance Method Summary collapse
-
#authenticated_uri ⇒ URI::Generic
Generates an authenticated URI for a the Valence API method.
-
#execute ⇒ D2L::Valence::Response
Sends the authenticated call on the Valence API.
-
#initialize(user_context:, http_method:, route:, route_params: {}, query_params: {}) ⇒ Request
constructor
API routes See D2L::Valence::UserContext.api_call for details on creating routes and route_params.
-
#path ⇒ String
Generates the final path for the authenticated call.
Constructor Details
#initialize(user_context:, http_method:, route:, route_params: {}, query_params: {}) ⇒ Request
API routes
See D2L::Valence::UserContext.api_call for details on creating routes and route_params
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/d2l/valence/request.rb', line 19 def initialize(user_context:, http_method:, route:, route_params: {}, query_params: {}) @user_context = user_context @app_context = user_context.app_context @http_method = http_method.upcase @route = route @route_params = route_params @query_params = query_params raise "HTTP Method #{@http_method} is unsupported" unless %w(GET PUT POST DELETE).include? @http_method end |
Instance Attribute Details
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
6 7 8 |
# File 'lib/d2l/valence/request.rb', line 6 def http_method @http_method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/d2l/valence/request.rb', line 6 def response @response end |
#user_context ⇒ Object (readonly)
Returns the value of attribute user_context.
6 7 8 |
# File 'lib/d2l/valence/request.rb', line 6 def user_context @user_context end |
Instance Method Details
#authenticated_uri ⇒ URI::Generic
Generates an authenticated URI for a the Valence API method
33 34 35 36 37 38 |
# File 'lib/d2l/valence/request.rb', line 33 def authenticated_uri @app_context.brightspace_host.to_uri( path: path, query: query ) end |
#execute ⇒ D2L::Valence::Response
Sends the authenticated call on the Valence API
43 44 45 46 47 48 49 |
# File 'lib/d2l/valence/request.rb', line 43 def execute raise "HTTP Method #{@http_method} is not implemented" if params.nil? @response = execute_call @user_context.server_skew = @response.server_skew @response end |
#path ⇒ String
Generates the final path for the authenticated call
54 55 56 57 58 59 60 |
# File 'lib/d2l/valence/request.rb', line 54 def path return @path unless @path.nil? substitute_keys_with(@route_params) substitute_keys_with(known_params) @path = @route end |