Class: Flipper::Adapters::FirebaseRemoteConfig::Client
- Inherits:
-
Object
- Object
- Flipper::Adapters::FirebaseRemoteConfig::Client
- Defined in:
- lib/flipper/adapters/firebase_remote_config/client.rb
Overview
Thin REST wrapper around the Firebase Remote Config v1 API.
Why hand-rolled instead of a generated client: there is no published service gem for ‘firebaseremoteconfig_v1` — neither bundled inside the (deprecated) `google-api-client` umbrella, nor as a stand-alone `google-apis-firebaseremoteconfig_v1`. We use `googleauth` directly for the OAuth2 service-account flow, and Net::HTTP for the two endpoints we actually need.
Instance Attribute Summary collapse
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
Instance Method Summary collapse
-
#fetch_template ⇒ Object
Returns [template_hash, etag_string].
-
#initialize(project_id:, credentials: nil, http: nil) ⇒ Client
constructor
A new instance of Client.
-
#publish_template(template, etag) ⇒ Object
Publishes a modified template.
Constructor Details
#initialize(project_id:, credentials: nil, http: nil) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 |
# File 'lib/flipper/adapters/firebase_remote_config/client.rb', line 28 def initialize(project_id:, credentials: nil, http: nil) @project_id = project_id @credentials = build_credentials(credentials) @http = http # injection seam for tests end |
Instance Attribute Details
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
26 27 28 |
# File 'lib/flipper/adapters/firebase_remote_config/client.rb', line 26 def project_id @project_id end |
Instance Method Details
#fetch_template ⇒ Object
Returns [template_hash, etag_string]. The template is the parsed JSON body as a Hash; etag is the opaque string from the ETag response header, which the server demands back on the next write.
37 38 39 40 41 |
# File 'lib/flipper/adapters/firebase_remote_config/client.rb', line 37 def fetch_template response = request(:get, template_path) ensure_success!(response) [JSON.parse(response.body), response['ETag']] end |
#publish_template(template, etag) ⇒ Object
Publishes a modified template. Raises ETagMismatch on 409/412 so the adapter can reload and retry; raises Error on any other failure.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/flipper/adapters/firebase_remote_config/client.rb', line 45 def publish_template(template, etag) response = request( :put, template_path, body: JSON.generate(template), headers: { 'Content-Type' => 'application/json; UTF-8', 'If-Match' => etag || '*' } ) raise ETagMismatch, response.body if etag_conflict?(response) ensure_success!(response) response end |