Class: Moodle::Api::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/moodle/api/client.rb', line 9

def initialize(options = {})
  configure(options)
end

Instance Attribute Details

#configurationObject



37
38
39
# File 'lib/moodle/api/client.rb', line 37

def configuration
  @configuration ||= Configuration.new
end

#filter_paramsObject (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

Parameters:

  • value

    the value to set the attribute token_service to.



7
8
9
# File 'lib/moodle/api/client.rb', line 7

def token_service=(value)
  @token_service = value
end

#web_service_nameObject (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(options = {}, &block)
  configuration.configure(options, &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_paramsObject



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_configurationObject



33
34
35
# File 'lib/moodle/api/client.rb', line 33

def reset_configuration
  configuration.reset
end