Class: School21::Client
- Inherits:
-
Object
- Object
- School21::Client
- Includes:
- CoreLibrary
- Defined in:
- lib/school21/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #auth_api ⇒ Object
- #authenticate! ⇒ Object
- #campuses_api ⇒ Object
- #clusters_api ⇒ Object
-
#initialize {|@config| ... } ⇒ Client
constructor
A new instance of Client.
- #participants_api ⇒ Object
- #projects_api ⇒ Object
Constructor Details
#initialize {|@config| ... } ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/school21/client.rb', line 13 def initialize(&block) raise 'A block must be given' unless block_given? raise 'You must provide block argument that represents config instance' if block.arity != 1 @config = GlobalConfig.new.base_uri_executor(BaseApi.method(:base_uri)) yield(@config) validate_credentials! initialize_logging if @config.enable_logging http_client = FaradayClient.new(@config.client_configuration) @config.client_configuration.set_http_client(http_client) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/school21/client.rb', line 7 def access_token @access_token end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/school21/client.rb', line 7 def config @config end |
Class Method Details
.configure ⇒ Object
10 |
# File 'lib/school21/client.rb', line 10 def configure(&) = new(&) |
Instance Method Details
#auth_api ⇒ Object
35 36 37 |
# File 'lib/school21/client.rb', line 35 def auth_api @auth_api ||= AuthApi.new(config) end |
#authenticate! ⇒ Object
29 30 31 32 33 |
# File 'lib/school21/client.rb', line 29 def authenticate! @access_token = request_access_token! initialize_auth_managers end |
#campuses_api ⇒ Object
49 50 51 52 |
# File 'lib/school21/client.rb', line 49 def campuses_api authenticate! if access_token.expired? CampusesApi.new(config) end |
#clusters_api ⇒ Object
54 55 56 57 |
# File 'lib/school21/client.rb', line 54 def clusters_api authenticate! if access_token.expired? ClustersApi.new(config) end |
#participants_api ⇒ Object
39 40 41 42 |
# File 'lib/school21/client.rb', line 39 def participants_api authenticate! if access_token.expired? ParticipantsApi.new(config) end |
#projects_api ⇒ Object
44 45 46 47 |
# File 'lib/school21/client.rb', line 44 def projects_api authenticate! if access_token.expired? ProjectsApi.new(config) end |