Class: Moodle::Api::Configuration

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

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.



18
19
20
21
22
# File 'lib/moodle/api/configuration.rb', line 18

def initialize options = {}
  @format = DEFAULT_FORMAT

  configure(options)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#serviceObject

Returns the value of attribute service.



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

def service
  @service
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#token_serviceObject



50
51
52
# File 'lib/moodle/api/configuration.rb', line 50

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

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

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



41
42
43
44
# File 'lib/moodle/api/configuration.rb', line 41

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

#resetObject



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

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

#token_api_urlObject



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

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

#web_service_api_urlObject



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

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