Class: Moodle::Api::Client
- Inherits:
-
Object
- Object
- Moodle::Api::Client
- Defined in:
- lib/moodle/api/client.rb
Overview
The client is responsible for making requests and delegating config setup to configuration
Instance Attribute Summary collapse
- #configuration ⇒ Object
-
#filter_params ⇒ Object
readonly
Returns the value of attribute filter_params.
-
#token_service ⇒ Object
writeonly
Sets the attribute token_service.
-
#web_service_name ⇒ Object
readonly
Returns the value of attribute web_service_name.
Instance Method Summary collapse
- #configure(options = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #make_request(web_service_name, filter_params = {}) ⇒ Object
- #request_params ⇒ Object
- #reset_configuration ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/moodle/api/client.rb', line 9 def initialize( = {}) configure() end |
Instance Attribute Details
#configuration ⇒ Object
37 38 39 |
# File 'lib/moodle/api/client.rb', line 37 def configuration @configuration ||= Configuration.new end |
#filter_params ⇒ Object (readonly)
Returns the value of attribute filter_params.
6 7 8 |
# File 'lib/moodle/api/client.rb', line 6 def filter_params @filter_params end |
#token_service=(value) ⇒ Object (writeonly)
Sets the attribute token_service
7 8 9 |
# File 'lib/moodle/api/client.rb', line 7 def token_service=(value) @token_service = value end |
#web_service_name ⇒ Object (readonly)
Returns the value of attribute web_service_name.
6 7 8 |
# File 'lib/moodle/api/client.rb', line 6 def web_service_name @web_service_name end |
Instance Method Details
#configure(options = {}, &block) ⇒ Object
29 30 31 |
# File 'lib/moodle/api/client.rb', line 29 def configure( = {}, &block) configuration.configure(, &block) end |
#make_request(web_service_name, filter_params = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/moodle/api/client.rb', line 13 def make_request(web_service_name, filter_params = {}) @web_service_name = web_service_name @filter_params = filter_params Request.new.post(configuration.web_service_api_url, request_params) end |
#request_params ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/moodle/api/client.rb', line 20 def request_params { params: filter_params.merge!(moodlewsrestformat: configuration.format, wsfunction: web_service_name, wstoken: configuration.token), headers: { 'Accept' => 'json' } } end |
#reset_configuration ⇒ Object
33 34 35 |
# File 'lib/moodle/api/client.rb', line 33 def reset_configuration configuration.reset end |