Skip to content

Commit

Permalink
feat(api): api update (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Dec 24, 2024
1 parent cb19bbb commit 15ddc64
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 97
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-77f4e8cf0fc3b3f18c894408f322af7988ae90606235fe5058442409142a33e1.yml
configured_endpoints: 101
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-726c25fdf0fdd4b7c5a9c36d30e33990d2a4b63c4260be340400f8ded23b578f.yml
19 changes: 19 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,22 @@ Methods:
- <code title="post /alerts/subscription_id/{subscription_id}">client.alerts.<a href="./src/resources/alerts.ts">createForSubscription</a>(subscriptionId, { ...params }) -> Alert</code>
- <code title="post /alerts/{alert_configuration_id}/disable">client.alerts.<a href="./src/resources/alerts.ts">disable</a>(alertConfigurationId, { ...params }) -> Alert</code>
- <code title="post /alerts/{alert_configuration_id}/enable">client.alerts.<a href="./src/resources/alerts.ts">enable</a>(alertConfigurationId, { ...params }) -> Alert</code>

# DimensionalPriceGroups

Types:

- <code><a href="./src/resources/dimensional-price-groups/dimensional-price-groups.ts">DimensionalPriceGroup</a></code>
- <code><a href="./src/resources/dimensional-price-groups/dimensional-price-groups.ts">DimensionalPriceGroups</a></code>

Methods:

- <code title="post /dimensional_price_groups">client.dimensionalPriceGroups.<a href="./src/resources/dimensional-price-groups/dimensional-price-groups.ts">create</a>({ ...params }) -> DimensionalPriceGroup</code>
- <code title="get /dimensional_price_groups/{dimensional_price_group_id}">client.dimensionalPriceGroups.<a href="./src/resources/dimensional-price-groups/dimensional-price-groups.ts">retrieve</a>(dimensionalPriceGroupId) -> DimensionalPriceGroup</code>
- <code title="get /dimensional_price_groups">client.dimensionalPriceGroups.<a href="./src/resources/dimensional-price-groups/dimensional-price-groups.ts">list</a>({ ...params }) -> DimensionalPriceGroupsPage</code>

## ExternalDimensionalPriceGroupID

Methods:

- <code title="get /dimensional_price_groups/external_dimensional_price_group_id/{external_dimensional_price_group_id}">client.dimensionalPriceGroups.externalDimensionalPriceGroupId.<a href="./src/resources/dimensional-price-groups/external-dimensional-price-group-id.ts">retrieve</a>(externalDimensionalPriceGroupId) -> DimensionalPriceGroup</code>
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ import {
Customers,
CustomersPage,
} from './resources/customers/customers';
import {
DimensionalPriceGroup,
DimensionalPriceGroupCreateParams,
DimensionalPriceGroupListParams,
DimensionalPriceGroups,
DimensionalPriceGroupsPage,
} from './resources/dimensional-price-groups/dimensional-price-groups';
import {
EventDeprecateResponse,
EventIngestParams,
Expand Down Expand Up @@ -277,6 +284,7 @@ export class Orb extends Core.APIClient {
subscriptions: API.Subscriptions = new API.Subscriptions(this);
webhooks: API.Webhooks = new API.Webhooks(this);
alerts: API.Alerts = new API.Alerts(this);
dimensionalPriceGroups: API.DimensionalPriceGroups = new API.DimensionalPriceGroups(this);

protected override defaultQuery(): Core.DefaultQuery | undefined {
return this._options.defaultQuery;
Expand Down Expand Up @@ -353,6 +361,7 @@ Orb.SubscriptionsPage = SubscriptionsPage;
Orb.SubscriptionFetchScheduleResponsesPage = SubscriptionFetchScheduleResponsesPage;
Orb.Alerts = Alerts;
Orb.AlertsPage = AlertsPage;
Orb.DimensionalPriceGroupsPage = DimensionalPriceGroupsPage;
export declare namespace Orb {
export type RequestOptions = Core.RequestOptions;

Expand Down Expand Up @@ -502,6 +511,14 @@ export declare namespace Orb {
type AlertEnableParams as AlertEnableParams,
};

export {
type DimensionalPriceGroups as DimensionalPriceGroups,
type DimensionalPriceGroup as DimensionalPriceGroup,
DimensionalPriceGroupsPage as DimensionalPriceGroupsPage,
type DimensionalPriceGroupCreateParams as DimensionalPriceGroupCreateParams,
type DimensionalPriceGroupListParams as DimensionalPriceGroupListParams,
};

export type AmountDiscount = API.AmountDiscount;
export type BillingCycleRelativeDate = API.BillingCycleRelativeDate;
export type Discount = API.Discount;
Expand Down
146 changes: 146 additions & 0 deletions src/resources/dimensional-price-groups/dimensional-price-groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import { isRequestOptions } from '../../core';
import * as Core from '../../core';
import * as Shared from '../shared';
import * as ExternalDimensionalPriceGroupIDAPI from './external-dimensional-price-group-id';
import { ExternalDimensionalPriceGroupID } from './external-dimensional-price-group-id';
import { Page, type PageParams } from '../../pagination';

export class DimensionalPriceGroups extends APIResource {
externalDimensionalPriceGroupId: ExternalDimensionalPriceGroupIDAPI.ExternalDimensionalPriceGroupID =
new ExternalDimensionalPriceGroupIDAPI.ExternalDimensionalPriceGroupID(this._client);

/**
* A dimensional price group is used to partition the result of a billable metric
* by a set of dimensions. Prices in a price group must specify the parition used
* to derive their usage.
*
* For example, suppose we have a billable metric that measures the number of
* widgets used and we want to charge differently depending on the color of the
* widget. We can create a price group with a dimension "color" and two prices: one
* that charges $10 per red widget and one that charges $20 per blue widget.
*/
create(
body: DimensionalPriceGroupCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<DimensionalPriceGroup> {
return this._client.post('/dimensional_price_groups', { body, ...options });
}

/**
* Fetch dimensional price group
*/
retrieve(
dimensionalPriceGroupId: string,
options?: Core.RequestOptions,
): Core.APIPromise<DimensionalPriceGroup> {
return this._client.get(`/dimensional_price_groups/${dimensionalPriceGroupId}`, options);
}

/**
* List dimensional price groups
*/
list(
query?: DimensionalPriceGroupListParams,
options?: Core.RequestOptions,
): Core.PagePromise<DimensionalPriceGroupsPage, DimensionalPriceGroup>;
list(options?: Core.RequestOptions): Core.PagePromise<DimensionalPriceGroupsPage, DimensionalPriceGroup>;
list(
query: DimensionalPriceGroupListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<DimensionalPriceGroupsPage, DimensionalPriceGroup> {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/dimensional_price_groups', DimensionalPriceGroupsPage, {
query,
...options,
});
}
}

export class DimensionalPriceGroupsPage extends Page<DimensionalPriceGroup> {}

/**
* A dimensional price group is used to partition the result of a billable metric
* by a set of dimensions. Prices in a price group must specify the parition used
* to derive their usage.
*/
export interface DimensionalPriceGroup {
id: string;

/**
* The billable metric associated with this dimensional price group. All prices
* associated with this dimensional price group will be computed using this
* billable metric.
*/
billable_metric_id: string;

/**
* The dimensions that this dimensional price group is defined over
*/
dimensions: Array<string>;

/**
* An alias for the dimensional price group
*/
external_dimensional_price_group_id: string | null;

/**
* User specified key-value pairs for the resource. If not present, this defaults
* to an empty dictionary. Individual keys can be removed by setting the value to
* `null`, and the entire metadata mapping can be cleared by setting `metadata` to
* `null`.
*/
metadata: Record<string, string>;

/**
* The name of the dimensional price group
*/
name: string;
}

export interface DimensionalPriceGroups {
data: Array<DimensionalPriceGroup>;

pagination_metadata: Shared.PaginationMetadata;
}

export interface DimensionalPriceGroupCreateParams {
billable_metric_id: string;

/**
* The set of keys (in order) used to disambiguate prices in the group.
*/
dimensions: Array<string>;

name: string;

external_dimensional_price_group_id?: string | null;

/**
* User-specified key/value pairs for the resource. Individual keys can be removed
* by setting the value to `null`, and the entire metadata mapping can be cleared
* by setting `metadata` to `null`.
*/
metadata?: Record<string, string | null> | null;
}

export interface DimensionalPriceGroupListParams extends PageParams {}

DimensionalPriceGroups.DimensionalPriceGroupsPage = DimensionalPriceGroupsPage;
DimensionalPriceGroups.ExternalDimensionalPriceGroupID = ExternalDimensionalPriceGroupID;

export declare namespace DimensionalPriceGroups {
export {
type DimensionalPriceGroup as DimensionalPriceGroup,
type DimensionalPriceGroups as DimensionalPriceGroups,
DimensionalPriceGroupsPage as DimensionalPriceGroupsPage,
type DimensionalPriceGroupCreateParams as DimensionalPriceGroupCreateParams,
type DimensionalPriceGroupListParams as DimensionalPriceGroupListParams,
};

export { ExternalDimensionalPriceGroupID as ExternalDimensionalPriceGroupID };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as DimensionalPriceGroupsAPI from './dimensional-price-groups';

export class ExternalDimensionalPriceGroupID extends APIResource {
/**
* Fetch dimensional price group by external ID
*/
retrieve(
externalDimensionalPriceGroupId: string,
options?: Core.RequestOptions,
): Core.APIPromise<DimensionalPriceGroupsAPI.DimensionalPriceGroup> {
return this._client.get(
`/dimensional_price_groups/external_dimensional_price_group_id/${externalDimensionalPriceGroupId}`,
options,
);
}
}
10 changes: 10 additions & 0 deletions src/resources/dimensional-price-groups/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export {
DimensionalPriceGroupsPage,
type DimensionalPriceGroups,
type DimensionalPriceGroup,
type DimensionalPriceGroupCreateParams,
type DimensionalPriceGroupListParams,
} from './dimensional-price-groups';
export { ExternalDimensionalPriceGroupID } from './external-dimensional-price-group-id';
7 changes: 7 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export {
type CustomerListParams,
type CustomerUpdateByExternalIDParams,
} from './customers/customers';
export {
DimensionalPriceGroupsPage,
type DimensionalPriceGroups,
type DimensionalPriceGroup,
type DimensionalPriceGroupCreateParams,
type DimensionalPriceGroupListParams,
} from './dimensional-price-groups/dimensional-price-groups';
export {
Events,
type EventUpdateResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Orb from 'orb-billing';
import { Response } from 'node-fetch';

const client = new Orb({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource dimensionalPriceGroups', () => {
test('create: only required params', async () => {
const responsePromise = client.dimensionalPriceGroups.create({
billable_metric_id: 'billable_metric_id',
dimensions: ['region', 'instance_type'],
name: 'name',
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('create: required and optional params', async () => {
const response = await client.dimensionalPriceGroups.create({
billable_metric_id: 'billable_metric_id',
dimensions: ['region', 'instance_type'],
name: 'name',
external_dimensional_price_group_id: 'external_dimensional_price_group_id',
metadata: { foo: 'string' },
});
});

test('retrieve', async () => {
const responsePromise = client.dimensionalPriceGroups.retrieve('dimensional_price_group_id');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('retrieve: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.dimensionalPriceGroups.retrieve('dimensional_price_group_id', {
path: '/_stainless_unknown_path',
}),
).rejects.toThrow(Orb.NotFoundError);
});

test('list', async () => {
const responsePromise = client.dimensionalPriceGroups.list();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('list: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(client.dimensionalPriceGroups.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
Orb.NotFoundError,
);
});

test('list: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.dimensionalPriceGroups.list(
{ cursor: 'cursor', limit: 1 },
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(Orb.NotFoundError);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Orb from 'orb-billing';
import { Response } from 'node-fetch';

const client = new Orb({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource externalDimensionalPriceGroupId', () => {
test('retrieve', async () => {
const responsePromise = client.dimensionalPriceGroups.externalDimensionalPriceGroupId.retrieve(
'external_dimensional_price_group_id',
);
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('retrieve: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.dimensionalPriceGroups.externalDimensionalPriceGroupId.retrieve(
'external_dimensional_price_group_id',
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(Orb.NotFoundError);
});
});

0 comments on commit 15ddc64

Please sign in to comment.