Class: Moodle::Api::Configuration

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

Overview

Handles all configuration settings required to interaction with a Moodle API

Constant Summary collapse

DEFAULT_FORMAT =
:json
DEFAULT_WEB_SERVICE_API_URL =
'/webservice/rest/server.php'
DEFAULT_TOKEN_API_URL =
'/login/token.php'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



20
21
22
23
24
# File 'lib/moodle/api/configuration.rb', line 20

def initialize(options = {})
  @format = DEFAULT_FORMAT

  configure(options)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#serviceObject

Returns the value of attribute service.



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

def service
  @service
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#token_serviceObject



52
53
54
# File 'lib/moodle/api/configuration.rb', line 52

def token_service
  @token_service ||= TokenGenerator.new(self)
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

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



43
44
45
46
# File 'lib/moodle/api/configuration.rb', line 43

def configure(options = {}, &block)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
  block.call(self) if block_given?
end

#resetObject



26
27
28
29
30
31
32
33
# File 'lib/moodle/api/configuration.rb', line 26

def reset
  @host = nil
  @username = nil
  @password = nil
  @service = nil
  @token = nil
  @format = DEFAULT_FORMAT
end

#token_api_urlObject



39
40
41
# File 'lib/moodle/api/configuration.rb', line 39

def token_api_url
  "#{host}#{DEFAULT_TOKEN_API_URL}"
end

#web_service_api_urlObject



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

def web_service_api_url
  "#{host}#{DEFAULT_WEB_SERVICE_API_URL}"
end