class SessionValidator::Client
Constants
- CREDENTIAL_SCOPE
- ESCHER_AUTH_OPTIONS
- NETWORK_ERRORS
- SERVICE_REQUEST_TIMEOUT
Public Instance Methods
filter_invalid(msids)
click to toggle source
# File lib/session_validator/client.rb, line 25 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
valid?(msid)
click to toggle source
# File lib/session_validator/client.rb, line 18 def valid?(msid) response_status = client.get("/sessions/#{msid}", nil, headers).status (200..299).include?(response_status) || (500..599).include?(response_status) rescue *NETWORK_ERRORS true end
Private Instance Methods
client()
click to toggle source
# File lib/session_validator/client.rb, line 38 def client Faraday.new(url) do |faraday| faraday.options[:open_timeout] = SERVICE_REQUEST_TIMEOUT faraday.options[:timeout] = SERVICE_REQUEST_TIMEOUT faraday.request :retry, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, methods: [:get, :post], exceptions: NETWORK_ERRORS faraday.use FaradayMiddleware::Escher::RequestSigner, escher_config faraday.adapter Faraday.default_adapter end end
escher_config()
click to toggle source
# File lib/session_validator/client.rb, line 60 def escher_config { credential_scope: CREDENTIAL_SCOPE, host: host, options: ESCHER_AUTH_OPTIONS, active_key: -> { ::Escher::Keypool.new.get_active_key("session_validator") } } end
headers()
click to toggle source
# File lib/session_validator/client.rb, line 69 def headers {"content-type" => "application/json"} end
host()
click to toggle source
# File lib/session_validator/client.rb, line 52 def host uri.hostname end
uri()
click to toggle source
# File lib/session_validator/client.rb, line 56 def uri URI.parse(SessionValidator.base_url) end
url()
click to toggle source
# File lib/session_validator/client.rb, line 48 def url uri.to_s end