Class: Growthbook::FeatureRepository
- Inherits:
-
Object
- Object
- Growthbook::FeatureRepository
- Defined in:
- lib/growthbook/feature_repository.rb
Overview
Optional class for fetching features from the GrowthBook API
Defined Under Namespace
Classes: FeatureFetchError, FeatureParseError
Instance Attribute Summary collapse
-
#decryption_key ⇒ Object
readonly
[String, nil] Optional key for decrypting an encrypted payload.
-
#endpoint ⇒ Object
readonly
[String] The SDK endpoint.
-
#features_json ⇒ Object
readonly
Parsed features JSON.
-
#saved_groups_json ⇒ Object
readonly
Parsed saved groups JSON (used by the $inGroup/$notInGroup operators).
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch! ⇒ Object
-
#initialize(endpoint:, decryption_key:) ⇒ FeatureRepository
constructor
A new instance of FeatureRepository.
Constructor Details
#initialize(endpoint:, decryption_key:) ⇒ FeatureRepository
Returns a new instance of FeatureRepository.
21 22 23 24 25 26 |
# File 'lib/growthbook/feature_repository.rb', line 21 def initialize(endpoint:, decryption_key:) @endpoint = endpoint @decryption_key = decryption_key @features_json = {} @saved_groups_json = {} end |
Instance Attribute Details
#decryption_key ⇒ Object (readonly)
[String, nil] Optional key for decrypting an encrypted payload
13 14 15 |
# File 'lib/growthbook/feature_repository.rb', line 13 def decryption_key @decryption_key end |
#endpoint ⇒ Object (readonly)
[String] The SDK endpoint
10 11 12 |
# File 'lib/growthbook/feature_repository.rb', line 10 def endpoint @endpoint end |
#features_json ⇒ Object (readonly)
Parsed features JSON
16 17 18 |
# File 'lib/growthbook/feature_repository.rb', line 16 def features_json @features_json end |
#saved_groups_json ⇒ Object (readonly)
Parsed saved groups JSON (used by the $inGroup/$notInGroup operators)
19 20 21 |
# File 'lib/growthbook/feature_repository.rb', line 19 def saved_groups_json @saved_groups_json end |
Instance Method Details
#fetch ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/growthbook/feature_repository.rb', line 28 def fetch uri = URI(endpoint) res = Net::HTTP.get_response(uri) @response = res.is_a?(Net::HTTPSuccess) ? res.body : nil return nil if response.nil? if use_decryption? parsed_decrypted_response else parsed_plain_text_response end rescue StandardError nil end |
#fetch! ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/growthbook/feature_repository.rb', line 45 def fetch! fetch raise FeatureFetchError if response.nil? raise FeatureParseError if features_json.nil? || features_json.empty? features_json end |