Skip to content

Commit e8e8475

Browse files
committed
feat(api): add usage analytics breakdown endpoint
Stainless-Generated-From: d6ccc6a
1 parent 3d598e8 commit e8e8475

55 files changed

Lines changed: 5639 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 47
1+
configured_endpoints: 48

src/Accounts/Usage/UsageGetParams.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
/**
1313
* Get the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.
1414
*
15+
* For an agency account, the returned usage is aggregated across the agency and all of its child accounts that are billed to it.
16+
*
17+
* The response is cached for 6 hours per account, date range and requested metrics.
18+
*
1519
* @see ImageKit\Services\Accounts\UsageService::get()
1620
*
1721
* @phpstan-type UsageGetParamsShape = array{endDate: string, startDate: string}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ImageKit\Accounts\UsageAnalytics;
6+
7+
use ImageKit\Core\Attributes\Required;
8+
use ImageKit\Core\Concerns\SdkModel;
9+
use ImageKit\Core\Contracts\BaseModel;
10+
11+
/**
12+
* @phpstan-type RequestBandwidthEntryShape = array{
13+
* bandwidthBytes: float, requestCount: float
14+
* }
15+
*/
16+
final class RequestBandwidthEntry implements BaseModel
17+
{
18+
/** @use SdkModel<RequestBandwidthEntryShape> */
19+
use SdkModel;
20+
21+
/**
22+
* Total bandwidth used in bytes.
23+
*/
24+
#[Required]
25+
public float $bandwidthBytes;
26+
27+
/**
28+
* Number of requests.
29+
*/
30+
#[Required]
31+
public float $requestCount;
32+
33+
/**
34+
* `new RequestBandwidthEntry()` is missing required properties by the API.
35+
*
36+
* To enforce required parameters use
37+
* ```
38+
* RequestBandwidthEntry::with(bandwidthBytes: ..., requestCount: ...)
39+
* ```
40+
*
41+
* Otherwise ensure the following setters are called
42+
*
43+
* ```
44+
* (new RequestBandwidthEntry)->withBandwidthBytes(...)->withRequestCount(...)
45+
* ```
46+
*/
47+
public function __construct()
48+
{
49+
$this->initialize();
50+
}
51+
52+
/**
53+
* Construct an instance from the required parameters.
54+
*
55+
* You must use named parameters to construct any parameters with a default value.
56+
*/
57+
public static function with(
58+
float $bandwidthBytes,
59+
float $requestCount
60+
): self {
61+
$self = new self;
62+
63+
$self['bandwidthBytes'] = $bandwidthBytes;
64+
$self['requestCount'] = $requestCount;
65+
66+
return $self;
67+
}
68+
69+
/**
70+
* Total bandwidth used in bytes.
71+
*/
72+
public function withBandwidthBytes(float $bandwidthBytes): self
73+
{
74+
$self = clone $this;
75+
$self['bandwidthBytes'] = $bandwidthBytes;
76+
77+
return $self;
78+
}
79+
80+
/**
81+
* Number of requests.
82+
*/
83+
public function withRequestCount(float $requestCount): self
84+
{
85+
$self = clone $this;
86+
$self['requestCount'] = $requestCount;
87+
88+
return $self;
89+
}
90+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ImageKit\Accounts\UsageAnalytics;
6+
7+
use ImageKit\Core\Attributes\Required;
8+
use ImageKit\Core\Concerns\SdkModel;
9+
use ImageKit\Core\Concerns\SdkParams;
10+
use ImageKit\Core\Contracts\BaseModel;
11+
12+
/**
13+
* **Note:** This API is currently in beta.
14+
*
15+
* Get the account analytics data between two dates. The response covers the period from the start date to the end date, both dates inclusive. Both dates are interpreted as UTC calendar days.
16+
*
17+
* The returned data is scoped to the requesting account only. Unlike `/v1/accounts/usage`, an agency account's analytics are not aggregated across its child accounts.
18+
*
19+
* The response is cached for 5 minutes per account and date range. Use `generatedAt` to check how fresh the returned data is.
20+
*
21+
* @see ImageKit\Services\Accounts\UsageAnalyticsService::get()
22+
*
23+
* @phpstan-type UsageAnalyticsGetParamsShape = array{
24+
* endDate: string, startDate: string
25+
* }
26+
*/
27+
final class UsageAnalyticsGetParams implements BaseModel
28+
{
29+
/** @use SdkModel<UsageAnalyticsGetParamsShape> */
30+
use SdkModel;
31+
use SdkParams;
32+
33+
/**
34+
* Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.
35+
*/
36+
#[Required]
37+
public string $endDate;
38+
39+
/**
40+
* Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.
41+
*/
42+
#[Required]
43+
public string $startDate;
44+
45+
/**
46+
* `new UsageAnalyticsGetParams()` is missing required properties by the API.
47+
*
48+
* To enforce required parameters use
49+
* ```
50+
* UsageAnalyticsGetParams::with(endDate: ..., startDate: ...)
51+
* ```
52+
*
53+
* Otherwise ensure the following setters are called
54+
*
55+
* ```
56+
* (new UsageAnalyticsGetParams)->withEndDate(...)->withStartDate(...)
57+
* ```
58+
*/
59+
public function __construct()
60+
{
61+
$this->initialize();
62+
}
63+
64+
/**
65+
* Construct an instance from the required parameters.
66+
*
67+
* You must use named parameters to construct any parameters with a default value.
68+
*/
69+
public static function with(string $endDate, string $startDate): self
70+
{
71+
$self = new self;
72+
73+
$self['endDate'] = $endDate;
74+
$self['startDate'] = $startDate;
75+
76+
return $self;
77+
}
78+
79+
/**
80+
* Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.
81+
*/
82+
public function withEndDate(string $endDate): self
83+
{
84+
$self = clone $this;
85+
$self['endDate'] = $endDate;
86+
87+
return $self;
88+
}
89+
90+
/**
91+
* Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.
92+
*/
93+
public function withStartDate(string $startDate): self
94+
{
95+
$self = clone $this;
96+
$self['startDate'] = $startDate;
97+
98+
return $self;
99+
}
100+
}

0 commit comments

Comments
 (0)