Class: SessionValidator::Client
- Inherits:
-
Object
- Object
- SessionValidator::Client
- Defined in:
- lib/session_validator/client.rb
Constant Summary collapse
- MSID_PATTERN =
/^[a-z0-9._]+_[0-9a-f]{14}\.[0-9]{8}$/.freeze
- CREDENTIAL_SCOPE =
"eu/session-validator/ems_request".freeze
- ESCHER_AUTH_OPTIONS =
{ algo_prefix: "EMS", vendor_key: "EMS", auth_header_name: "X-Ems-Auth", date_header_name: "X-Ems-Date" }.freeze
- SERVICE_REQUEST_TIMEOUT =
2.freeze
- NETWORK_ERRORS =
Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed] - ['Timeout::Error']
Instance Method Summary collapse
- #filter_invalid(msids) ⇒ Object deprecated Deprecated.
-
#initialize(use_escher: true) ⇒ Client
constructor
A new instance of Client.
- #session_data(token) ⇒ Object
- #valid?(id) ⇒ Boolean
Constructor Details
#initialize(use_escher: true) ⇒ Client
Returns a new instance of Client.
19 20 21 |
# File 'lib/session_validator/client.rb', line 19 def initialize(use_escher: true) @use_escher = use_escher end |
Instance Method Details
#filter_invalid(msids) ⇒ Object
Deprecated.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/session_validator/client.rb', line 43 def filter_invalid(msids) response = client.post("/sessions/filter", JSON.generate({ msids: msids }), headers) if response.status == 200 JSON.parse(response.body) else [] end rescue *NETWORK_ERRORS [] end |
#session_data(token) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/session_validator/client.rb', line 31 def session_data(token) response = client.get("/sessions", nil, headers.merge( token)) case response.status when 200 then JSON.parse(response.body) when 400..499 then raise SessionValidator::SessionDataNotFound when 500.. then raise SessionValidator::SessionDataError, "Service unreachable" end rescue *NETWORK_ERRORS raise SessionValidator::SessionDataError, "Service unreachable" end |
#valid?(id) ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/session_validator/client.rb', line 23 def valid?(id) if id.match(MSID_PATTERN) valid_by_msid? id else valid_by_session_data_token? id end end |