Class: Vapi::AsyncAnalyticsClient

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::AsyncAnalyticsClient

Parameters:



68
69
70
# File 'lib/vapi_server_sdk/analytics/client.rb', line 68

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::AsyncRequestClient (readonly)



64
65
66
# File 'lib/vapi_server_sdk/analytics/client.rb', line 64

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:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vapi_server_sdk/analytics/client.rb', line 91

def get(queries:, request_options: nil)
  Async do
    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
end