Class: School21::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/school21/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|@config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



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_tokenObject (readonly)

Returns the value of attribute access_token.



7
8
9
# File 'lib/school21/client.rb', line 7

def access_token
  @access_token
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/school21/client.rb', line 7

def config
  @config
end

Class Method Details

.configureObject



10
# File 'lib/school21/client.rb', line 10

def configure(&) = new(&)

Instance Method Details

#auth_apiObject



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_apiObject



49
50
51
52
# File 'lib/school21/client.rb', line 49

def campuses_api
  authenticate! if access_token.expired?
  CampusesApi.new(config)
end

#clusters_apiObject



54
55
56
57
# File 'lib/school21/client.rb', line 54

def clusters_api
  authenticate! if access_token.expired?
  ClustersApi.new(config)
end

#participants_apiObject



39
40
41
42
# File 'lib/school21/client.rb', line 39

def participants_api
  authenticate! if access_token.expired?
  ParticipantsApi.new(config)
end

#projects_apiObject



44
45
46
47
# File 'lib/school21/client.rb', line 44

def projects_api
  authenticate! if access_token.expired?
  ProjectsApi.new(config)
end