Class: CDP::Client

Inherits:
Object
  • Object
show all
Includes:
Retryable, Configuration
Defined in:
lib/cdp/client.rb

Constant Summary collapse

AVAILABLE_PRIORITIES =
%i[low normal high]

Constants included from Configuration

Configuration::CDP_CORE_SERVICE_URL

Constants included from Retryable

Retryable::CDP_CLIENT_RETRYABLE_ERRORS, Retryable::DEFAULT_CDP_CLIENT_RETRYABLE_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Retryable

#retry_block

Constructor Details

#initialize(service_name:, priority: :normal, url: CDP_CORE_SERVICE_URL, secure: :this_channel_is_insecure, retries: 3) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
# File 'lib/cdp/client.rb', line 12

def initialize(service_name:, priority: :normal, url: CDP_CORE_SERVICE_URL, secure: :this_channel_is_insecure, retries: 3)
  validate_priorities(priority)
  @service_name = service_name
  @priority = priority
  @retries = retries
  @service = CDP::Service::Stub.new(url, secure)
  @search_service = CDP::SearchService::Stub.new(url, secure)
  @legacy = CDP::Legacy::Service::Stub.new(url, secure)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args) ⇒ Object



44
45
46
# File 'lib/cdp/client.rb', line 44

def method_missing(method_name, *_args)
  Query::Actions.new(self, method_name)
end

Instance Attribute Details

#legacyObject (readonly)

Returns the value of attribute legacy.



8
9
10
# File 'lib/cdp/client.rb', line 8

def legacy
  @legacy
end

Instance Method Details

#execute_async(transaction, priority: @priority) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/cdp/client.rb', line 30

def execute_async(transaction, priority: @priority)
  validate_priorities(priority)
  response = retry_block(limit: @retries) {
    @service.execute_async(transaction, (priority: priority))
  }
  response
end

#execute_sync(transaction, priority: @priority) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cdp/client.rb', line 22

def execute_sync(transaction, priority: @priority)
  validate_priorities(priority)
  response = retry_block(limit: @retries) {
    @service.execute_sync(transaction, (priority: priority))
  }
  response
end

#search(request:) ⇒ Object



38
39
40
41
42
# File 'lib/cdp/client.rb', line 38

def search(request:)
  retry_block(limit: @retries) {
    @search_service.execute(request)
  }
end