Class: Vapi::AnalyticsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/analytics/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::AnalyticsClient

Parameters:



16
17
18
# File 'lib/vapi_server_sdk/analytics/client.rb', line 16

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::RequestClient (readonly)

Returns:



12
13
14
# File 'lib/vapi_server_sdk/analytics/client.rb', line 12

def request_client
  @request_client
end

Instance Method Details

#get(queries:, request_options: nil) ⇒ Array<Vapi::AnalyticsQueryResult>

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.analytics.get(queries: [{ table: "call", name: "name", operations: [{ operation: SUM, column: ID }] }])

Parameters:

  • queries (Array<Hash>)

    This is the list of metric queries you want to perform.Request of type Array<Vapi::AnalyticsQuery>, as a Hash

    • :table (String)

    • :group_by (Array<Vapi::AnalyticsQueryGroupByItem>)

    • :name (String)

    • :time_range (Hash)

      • :step (Vapi::TimeRangeStep)

      • :start (DateTime)

      • :end_ (DateTime)

      • :timezone (String)

    • :operations (Array<Vapi::AnalyticsOperation>)

  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vapi_server_sdk/analytics/client.rb', line 39

def get(queries:, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), queries: queries }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/analytics"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    Vapi::AnalyticsQueryResult.from_json(json_object: item)
  end
end