Class: Prefab::Client
- Inherits:
-
Object
- Object
- Prefab::Client
- Defined in:
- lib/prefab/client.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#shared_cache ⇒ Object
readonly
Returns the value of attribute shared_cache.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #config_client(timeout: 10.0) ⇒ Object
-
#initialize(api_key:, logger: nil, stats: nil, shared_cache: nil, local: false, namespace: "") ⇒ Client
constructor
A new instance of Client.
- #ratelimit_client(timeout: 5.0) ⇒ Object
Constructor Details
#initialize(api_key:, logger: nil, stats: nil, shared_cache: nil, local: false, namespace: "") ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prefab/client.rb', line 5 def initialize(api_key:, logger: nil, stats: nil, # receives increment("prefab.limitcheck", {:tags=>["policy_group:page_view", "pass:true"]}) shared_cache: nil, # Something that quacks like Rails.cache ideally memcached local: false, namespace: "" ) @logger = (logger || Logger.new($stdout)).tap do |log| log.progname = "Prefab" if log.respond_to? :progname= end @stats = (stats || NoopStats.new) @shared_cache = (shared_cache || NoopCache.new) @account_id = api_key.split("|")[0].to_i @namespace = namespace @interceptor = AuthInterceptor.new(api_key) @creds = GRPC::Core::ChannelCredentials.new(ssl_certs) @channel = GRPC::Core::Channel.new('api.prefab.cloud:8443', nil, @creds) if local @channel = GRPC::Core::Channel.new('localhost:8443', nil, :this_channel_is_insecure) end end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
3 4 5 |
# File 'lib/prefab/client.rb', line 3 def account_id @account_id end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/prefab/client.rb', line 3 def logger @logger end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/prefab/client.rb', line 3 def namespace @namespace end |
#shared_cache ⇒ Object (readonly)
Returns the value of attribute shared_cache.
3 4 5 |
# File 'lib/prefab/client.rb', line 3 def shared_cache @shared_cache end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
3 4 5 |
# File 'lib/prefab/client.rb', line 3 def stats @stats end |
Instance Method Details
#config_client(timeout: 10.0) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/prefab/client.rb', line 29 def config_client(timeout: 10.0) @config_client ||= Prefab::ConfigClient.new(Prefab::ConfigService::Stub.new(nil, @creds, channel_override: @channel, timeout: timeout, interceptors: [@interceptor]), self) end |
#ratelimit_client(timeout: 5.0) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/prefab/client.rb', line 38 def ratelimit_client(timeout: 5.0) @ratelimit_client ||= Prefab::RateLimitClient.new(Prefab::RateLimitService::Stub.new(nil, @creds, channel_override: @channel, timeout: timeout, interceptors: [@interceptor]), self) end |