Class: Moodle::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle/api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client



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

def initialize options = {}
  configure(options)
end

Instance Attribute Details

#filter_paramsObject (readonly)

Returns the value of attribute filter_params.



4
5
6
# File 'lib/moodle/api/client.rb', line 4

def filter_params
  @filter_params
end

#token_service=(value) ⇒ Object (writeonly)

Sets the attribute token_service



5
6
7
# File 'lib/moodle/api/client.rb', line 5

def token_service=(value)
  @token_service = value
end

#web_service_nameObject (readonly)

Returns the value of attribute web_service_name.



4
5
6
# File 'lib/moodle/api/client.rb', line 4

def web_service_name
  @web_service_name
end

Instance Method Details

#configurationObject



35
36
37
# File 'lib/moodle/api/client.rb', line 35

def configuration
  @configuration ||= Configuration.new
end

#configure(options = {}, &block) ⇒ Object



27
28
29
# File 'lib/moodle/api/client.rb', line 27

def configure options = {}, &block
  configuration.configure(options, &block)
end

#make_request(web_service_name, filter_params = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/moodle/api/client.rb', line 11

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



18
19
20
21
22
23
24
25
# File 'lib/moodle/api/client.rb', line 18

def request_params
  {
    params: filter_params.merge!({ moodlewsrestformat: configuration.format,
                                   wsfunction: web_service_name,
                                   wstoken: configuration.token }),
    headers: { 'Accept' => 'json' }
  }
end

#reset_configurationObject



31
32
33
# File 'lib/moodle/api/client.rb', line 31

def reset_configuration
  configuration.reset
end