Class: XodClient::Connection
- Inherits:
-
Object
- Object
- XodClient::Connection
- Includes:
- DataEndpoints, InfoEndpoints
- Defined in:
- lib/xod_client/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#estab ⇒ Object
readonly
Returns the value of attribute estab.
-
#relying_party ⇒ Object
readonly
Returns the value of attribute relying_party.
-
#response_logger ⇒ Object
readonly
Returns the value of attribute response_logger.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_expires_at ⇒ Object
readonly
Returns the value of attribute token_expires_at.
-
#token_refreshed_proc ⇒ Object
readonly
Returns the value of attribute token_refreshed_proc.
Instance Method Summary collapse
- #endpoint(endpoint_name = nil, **params) ⇒ Object
- #ensure_token ⇒ Object
- #faraday(**options) ⇒ Object
-
#initialize(relying_party, estab, secret, token: nil, token_expires_at: nil, response_logger: nil, token_refreshed_proc: nil) ⇒ Connection
constructor
rubocop:disable Metrics/ParameterLists.
- #refresh_token ⇒ Object
- #valid_token? ⇒ Boolean
Methods included from DataEndpoints
#groups, #health, #school_info, #staff, #students, #timetable, #timetable_model, #timetable_structure
Methods included from InfoEndpoints
#gdpr_ids, #logs, #queries, #scopes, #token_details, #usage
Constructor Details
#initialize(relying_party, estab, secret, token: nil, token_expires_at: nil, response_logger: nil, token_refreshed_proc: nil) ⇒ Connection
rubocop:disable Metrics/ParameterLists
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/xod_client/connection.rb', line 19 def initialize(, estab, secret, token: nil, token_expires_at: nil, response_logger: nil, token_refreshed_proc: nil) @relying_party = @estab = estab @secret = secret @token = token @token_expires_at = token_expires_at @response_logger = response_logger @token_refreshed_proc = token_refreshed_proc @config = Config.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def config @config end |
#estab ⇒ Object (readonly)
Returns the value of attribute estab.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def estab @estab end |
#relying_party ⇒ Object (readonly)
Returns the value of attribute relying_party.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def @relying_party end |
#response_logger ⇒ Object (readonly)
Returns the value of attribute response_logger.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def response_logger @response_logger end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def secret @secret end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def token @token end |
#token_expires_at ⇒ Object (readonly)
Returns the value of attribute token_expires_at.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def token_expires_at @token_expires_at end |
#token_refreshed_proc ⇒ Object (readonly)
Returns the value of attribute token_refreshed_proc.
15 16 17 |
# File 'lib/xod_client/connection.rb', line 15 def token_refreshed_proc @token_refreshed_proc end |
Instance Method Details
#endpoint(endpoint_name = nil, **params) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/xod_client/connection.rb', line 31 def endpoint(endpoint_name = nil, **params) endpoint_name ||= params.delete(:endpoint_name) || raise(ArgumentError, 'Endpoint name should be provided') ensure_token EndpointCall.new(self, endpoint_name, params) end |
#ensure_token ⇒ Object
38 39 40 |
# File 'lib/xod_client/connection.rb', line 38 def ensure_token refresh_token unless valid_token? end |
#faraday(**options) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/xod_client/connection.rb', line 51 def faraday(**) Faraday.new() do |conn| conn.request :retry, config. conn.response :logger, response_logger, bodies: true if response_logger conn.adapter :net_http conn.headers['Content-Type'] = 'application/json' conn.headers['User-Agent'] = config.user_agent end end |
#refresh_token ⇒ Object
42 43 44 45 |
# File 'lib/xod_client/connection.rb', line 42 def refresh_token @token, @token_expires_at = TokenRefresher.new(self).perform token_refreshed_proc&.call(token: @token, token_expires_at: @token_expires_at) end |
#valid_token? ⇒ Boolean
47 48 49 |
# File 'lib/xod_client/connection.rb', line 47 def valid_token? token && token_expires_at&.future? end |