Class: Featureflip::Http::Client
- Inherits:
-
Object
- Object
- Featureflip::Http::Client
- Defined in:
- lib/featureflip/http/client.rb
Instance Method Summary collapse
- #close ⇒ Object
- #get_flag(key) ⇒ Object
- #get_flags ⇒ Object
-
#initialize(sdk_key, config) ⇒ Client
constructor
A new instance of Client.
-
#parse_flags_response(data) ⇒ Object
Parse a GET /v1/sdk/flags-shaped snapshot into models.
- #post_events(events) ⇒ Object
Constructor Details
#initialize(sdk_key, config) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/featureflip/http/client.rb', line 8 def initialize(sdk_key, config) @sdk_key = sdk_key @config = config @base_url = config.base_url end |
Instance Method Details
#close ⇒ Object
37 38 39 |
# File 'lib/featureflip/http/client.rb', line 37 def close # No persistent connection to close with net/http end |
#get_flag(key) ⇒ Object
28 29 30 31 |
# File 'lib/featureflip/http/client.rb', line 28 def get_flag(key) response = request(:get, "/v1/sdk/flags/#{key}") parse_flag(JSON.parse(response.body)) end |
#get_flags ⇒ Object
14 15 16 17 |
# File 'lib/featureflip/http/client.rb', line 14 def get_flags response = request(:get, "/v1/sdk/flags") parse_flags_response(JSON.parse(response.body)) end |
#parse_flags_response(data) ⇒ Object
Parse a GET /v1/sdk/flags-shaped snapshot into models. Reused for the
connect-time sync SSE snapshot, which carries the identical payload
shape inline (no extra HTTP round-trip).
22 23 24 25 26 |
# File 'lib/featureflip/http/client.rb', line 22 def parse_flags_response(data) flags = (data["flags"] || []).map { |f| parse_flag(f) } segments = (data["segments"] || []).map { |s| parse_segment(s) } [flags, segments] end |
#post_events(events) ⇒ Object
33 34 35 |
# File 'lib/featureflip/http/client.rb', line 33 def post_events(events) request(:post, "/v1/sdk/events", { events: events }) end |