Class: Moodle::Api::Configuration
- Inherits:
-
Object
- Object
- Moodle::Api::Configuration
- 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
-
#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.
18 19 20 21 22 |
# File 'lib/moodle/api/configuration.rb', line 18 def initialize = {} @format = DEFAULT_FORMAT configure() end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/moodle/api/configuration.rb', line 5 def format @format end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/moodle/api/configuration.rb', line 5 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/moodle/api/configuration.rb', line 5 def password @password end |
#service ⇒ Object
Returns the value of attribute service.
5 6 7 |
# File 'lib/moodle/api/configuration.rb', line 5 def service @service end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/moodle/api/configuration.rb', line 5 def token @token end |
#token_service ⇒ Object
50 51 52 |
# File 'lib/moodle/api/configuration.rb', line 50 def token_service @token_service ||= TokenGenerator.new(self) end |
#username ⇒ Object
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 = {}, &block .each { |key, value| instance_variable_set("@#{key}", value) } block.call(self) if block_given? end |
#reset ⇒ Object
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_url ⇒ Object
37 38 39 |
# File 'lib/moodle/api/configuration.rb', line 37 def token_api_url "#{host}#{DEFAULT_TOKEN_API_URL}" end |
#web_service_api_url ⇒ Object
33 34 35 |
# File 'lib/moodle/api/configuration.rb', line 33 def web_service_api_url "#{host}#{DEFAULT_WEB_SERVICE_API_URL}" end |