Module: RDStation::RetryableRequest
Constant Summary collapse
- MAX_RETRIES =
1
Instance Method Summary collapse
- #refresh_access_token(authorization) ⇒ Object
- #retry_possible?(authorization) ⇒ Boolean
- #retryable_request(authorization) ⇒ Object
Instance Method Details
#refresh_access_token(authorization) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rdstation/retryable_request.rb', line 27 def refresh_access_token() client = RDStation::Authentication.new response = client.update_access_token(.refresh_token) .access_token = response['access_token'] .access_token_expires_in = response['expires_in'] RDStation.configuration&.access_token_refresh_callback&.call() end |
#retry_possible?(authorization) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/rdstation/retryable_request.rb', line 19 def retry_possible?() [ RDStation.configuration&.client_id, RDStation.configuration&.client_secret, .refresh_token ].all? end |
#retryable_request(authorization) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rdstation/retryable_request.rb', line 6 def retryable_request() retries = 0 begin yield rescue ::RDStation::Error::ExpiredAccessToken => e raise if !retry_possible?() || retries >= MAX_RETRIES retries += 1 refresh_access_token() retry end end |