Class: FIS::Client::Base
- Inherits:
-
Object
- Object
- FIS::Client::Base
- Defined in:
- lib/fis/client/base.rb
Constant Summary collapse
- BASE_URL =
ENV.fetch('FIS_CLIENT_BASE_URL', 'https://portal.flatironschool.com')
- API_ROOT =
'/api/v1'- CLIENT_ERROR_STATUSES =
[400, 401, 403, 407, 422].freeze
- SERVER_ERROR_STATUSES =
(500..511).to_a.freeze
- ERROR_STATUSES =
(CLIENT_ERROR_STATUSES + SERVER_ERROR_STATUSES).freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(token:) ⇒ Base
constructor
A new instance of Base.
- #user ⇒ Object
- #valid_token? ⇒ Boolean
Constructor Details
#initialize(token:) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fis/client/base.rb', line 16 def initialize(token:) url = [BASE_URL, API_ROOT].join @client = Faraday.new(url: url) do |conn| conn. :Bearer, token conn.response :json, content_type: 'application/json', parser_options: { object_class: OpenStruct } conn.request :retry, max: 3, interval: 2, interval_randomness: 0.5, backoff_factor: 2, methods: Faraday::Request::Retry::IDEMPOTENT_METHODS + [:post], retry_statuses: ERROR_STATUSES, exceptions: Faraday::Request::Retry::DEFAULT_EXCEPTIONS conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/fis/client/base.rb', line 14 def client @client end |