Class: Moodle::Api::Configuration
- Inherits:
-
Object
- Object
- Moodle::Api::Configuration
- 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
-
#format ⇒ Object
Returns the value of attribute format.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#service ⇒ Object
Returns the value of attribute service.
-
#token ⇒ Object
Returns the value of attribute token.
- #token_service ⇒ Object
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #configure(options = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #reset ⇒ Object
- #token_api_url ⇒ Object
- #web_service_api_url ⇒ Object
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( = {}) @format = DEFAULT_FORMAT configure() end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/moodle/api/configuration.rb', line 7 def format @format end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/moodle/api/configuration.rb', line 7 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/moodle/api/configuration.rb', line 7 def password @password end |
#service ⇒ Object
Returns the value of attribute service.
7 8 9 |
# File 'lib/moodle/api/configuration.rb', line 7 def service @service end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/moodle/api/configuration.rb', line 7 def token @token end |
#token_service ⇒ Object
52 53 54 |
# File 'lib/moodle/api/configuration.rb', line 52 def token_service @token_service ||= TokenGenerator.new(self) end |
#username ⇒ Object
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( = {}, &block) .each { |key, value| instance_variable_set("@#{key}", value) } block.call(self) if block_given? end |
#reset ⇒ Object
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_url ⇒ Object
39 40 41 |
# File 'lib/moodle/api/configuration.rb', line 39 def token_api_url "#{host}#{DEFAULT_TOKEN_API_URL}" end |
#web_service_api_url ⇒ Object
35 36 37 |
# File 'lib/moodle/api/configuration.rb', line 35 def web_service_api_url "#{host}#{DEFAULT_WEB_SERVICE_API_URL}" end |