Class: GoFlippy::Client
- Inherits:
-
Object
- Object
- GoFlippy::Client
- Includes:
- Logger
- Defined in:
- lib/goflippy-ruby/client.rb
Constant Summary
Constants included from Logger
Instance Method Summary collapse
- #enabled?(key, uid, default) ⇒ Boolean
-
#initialize(api_key, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #register(uid, groups = []) ⇒ Object
- #start ⇒ Object
Methods included from Logger
debug, error, fatal, info, logger, logger=, unknown, warn
Constructor Details
#initialize(api_key, opts = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 |
# File 'lib/goflippy-ruby/client.rb', line 5 def initialize(api_key, opts = {}) @api_key = api_key @config = opts&.empty? ? Config.default : Config.new(opts) @store = MemoryStore.new @http_client = HttpClient.new(@api_key, @config) @poller = Poller.new(@config.polling_interval, @http_client, @store) end |
Instance Method Details
#enabled?(key, uid, default) ⇒ Boolean
18 19 20 21 |
# File 'lib/goflippy-ruby/client.rb', line 18 def enabled?(key, uid, default) uids = @store.find(key) uids&.dig(uid.to_sym) || default end |
#register(uid, groups = []) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/goflippy-ruby/client.rb', line 23 def register(uid, groups = []) @store.put(uid, true) params = { uid: uid, groups: groups } @http_client.post('/users', params) end |