Class: OpenFeature::OFREP::Client
- Inherits:
-
Object
- Object
- OpenFeature::OFREP::Client
- Defined in:
- lib/openfeature/ofrep/provider/client.rb
Constant Summary collapse
- REASON_MAP =
{ "STATIC" => SDK::Provider::Reason::STATIC, "DEFAULT" => SDK::Provider::Reason::DEFAULT, "TARGETING_MATCH" => SDK::Provider::Reason::TARGETING_MATCH, "SPLIT" => SDK::Provider::Reason::SPLIT, "CACHED" => SDK::Provider::Reason::CACHED, "DISABLED" => SDK::Provider::Reason::DISABLED, "UNKNOWN" => SDK::Provider::Reason::UNKNOWN, "STALE" => SDK::Provider::Reason::STALE, "ERROR" => SDK::Provider::Reason::ERROR }.freeze
- ERROR_CODE_MAP =
{ "PROVIDER_NOT_READY" => SDK::Provider::ErrorCode::PROVIDER_NOT_READY, "FLAG_NOT_FOUND" => SDK::Provider::ErrorCode::FLAG_NOT_FOUND, "PARSE_ERROR" => SDK::Provider::ErrorCode::PARSE_ERROR, "TYPE_MISMATCH" => SDK::Provider::ErrorCode::TYPE_MISMATCH, "TARGETING_KEY_MISSING" => SDK::Provider::ErrorCode::TARGETING_KEY_MISSING, "INVALID_CONTEXT" => SDK::Provider::ErrorCode::INVALID_CONTEXT, "GENERAL" => SDK::Provider::ErrorCode::GENERAL }.freeze
Instance Method Summary collapse
- #evaluate(flag_key:, evaluation_context:) ⇒ Object
-
#initialize(configuration:) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(configuration:) ⇒ Client
Returns a new instance of Client.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/openfeature/ofrep/provider/client.rb', line 35 def initialize(configuration:) @configuration = configuration @retry_lock = Mutex.new = {timeout: configuration.timeout} @faraday_connection = Faraday.new( url: configuration.base_url, headers: build_headers, request: ) do |f| f.adapter :net_http_persistent do |http| http.idle_timeout = 30 end end end |
Instance Method Details
#evaluate(flag_key:, evaluation_context:) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/openfeature/ofrep/provider/client.rb', line 50 def evaluate(flag_key:, evaluation_context:) check_retry_after request = evaluation_request(evaluation_context) response = @faraday_connection.post("/ofrep/v1/evaluate/flags/#{CGI.escape(flag_key)}") do |req| req.body = request.to_json end case response.status when 200 parse_success_response(response) when 400 parse_error_response(response) when 401, 403 raise OpenFeature::OFREP::UnauthorizedError.new(response) when 404 raise OpenFeature::OFREP::FlagNotFoundError.new(response, flag_key) when 429 parse_retry_later_header(response) raise OpenFeature::OFREP::RateLimited.new(response) else raise OpenFeature::OFREP::InternalServerError.new(response) end end |