// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * AdSense Platform API Client for Deno * ==================================== * * * * Docs: https://developers.google.com/adsense/platforms/ * Source: https://googleapis.deno.dev/v1/adsenseplatform:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; export class AdSensePlatform { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://adsenseplatform.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Closes a sub-account. * * @param name Required. Account to close. Format: platforms/{platform}/accounts/{account_id} */ async platformsAccountsClose(name: string, req: CloseAccountRequest): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:close`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as CloseAccountResponse; } /** * Creates a sub-account. * * @param parent Required. Platform to create an account for. Format: platforms/{platform} */ async platformsAccountsCreate(parent: string, req: Account): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/accounts`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Account; } /** * Creates an account event. * * @param parent Required. Account to log events about. Format: platforms/{platform}/accounts/{account} */ async platformsAccountsEventsCreate(parent: string, req: Event): Promise { req = serializeEvent(req); const url = new URL(`${this.#baseUrl}v1/${ parent }/events`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return deserializeEvent(data); } /** * Gets information about the selected sub-account. * * @param name Required. Account to get information about. Format: platforms/{platform}/accounts/{account_id} */ async platformsAccountsGet(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Account; } /** * Lists a partial view of sub-accounts for a specific parent account. * * @param parent Required. Platform who parents the accounts. Format: platforms/{platform} */ async platformsAccountsList(parent: string, opts: PlatformsAccountsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/accounts`); if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListAccountsResponse; } /** * Looks up information about a sub-account for a specified * creation_request_id. If no account exists for the given * creation_request_id, returns 404. * * @param parent Required. Platform who parents the account. Format: platforms/{platform} */ async platformsAccountsLookup(parent: string, opts: PlatformsAccountsLookupOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/accounts:lookup`); if (opts.creationRequestId !== undefined) { url.searchParams.append("creationRequestId", String(opts.creationRequestId)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as LookupAccountResponse; } /** * Creates a site for a specified account. * * @param parent Required. Account to create site. Format: platforms/{platform}/accounts/{account_id} */ async platformsAccountsSitesCreate(parent: string, req: Site): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/sites`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Site; } /** * Deletes a site from a specified account. * * @param name Required. The name of the site to delete. Format: platforms/{platform}/accounts/{account}/sites/{site} */ async platformsAccountsSitesDelete(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Gets a site from a specified sub-account. * * @param name Required. The name of the site to retrieve. Format: platforms/{platform}/accounts/{account}/sites/{site} */ async platformsAccountsSitesGet(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Site; } /** * Lists sites for a specific account. * * @param parent Required. The account which owns the sites. Format: platforms/{platform}/accounts/{account} */ async platformsAccountsSitesList(parent: string, opts: PlatformsAccountsSitesListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/sites`); if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListSitesResponse; } /** * Requests the review of a site. The site should be in REQUIRES_REVIEW or * NEEDS_ATTENTION state. Note: Make sure you place an [ad * tag](https://developers.google.com/adsense/platforms/direct/ad-tags) on * your site before requesting a review. * * @param name Required. The name of the site to submit for review. Format: platforms/{platform}/accounts/{account}/sites/{site} */ async platformsAccountsSitesRequestReview(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:requestReview`); const data = await request(url.href, { client: this.#client, method: "POST", }); return data as RequestSiteReviewResponse; } } /** * Representation of an Account. */ export interface Account { /** * Output only. Creation time of the account. */ readonly createTime?: Date; /** * Required. An opaque token that uniquely identifies the account among all * the platform's accounts. This string may contain at most 64 non-whitespace * ASCII characters, but otherwise has no predefined structure. However, it is * expected to be a platform-specific identifier for the user creating the * account, so that only a single account can be created for any given user. * This field must not contain any information that is recognizable as * personally identifiable information. e.g. it should not be an email address * or login name. Once an account has been created, a second attempt to create * an account using the same creation_request_id will result in an * ALREADY_EXISTS error. */ creationRequestId?: string; /** * Display name of this account. */ displayName?: string; /** * Output only. Resource name of the account. Format: * platforms/pub-[0-9]+/accounts/pub-[0-9]+ */ readonly name?: string; /** * Required. Input only. CLDR region code of the country/region of the * address. Set this to country code of the child account if known, otherwise * to your own country code. */ regionCode?: string; /** * Output only. Approval state of the account. */ readonly state?: | "STATE_UNSPECIFIED" | "UNCHECKED" | "APPROVED" | "DISAPPROVED"; /** * Required. The IANA TZ timezone code of this account. For more information, * see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. This * field is used for reporting. It is recommended to set it to the same value * for all child accounts. */ timeZone?: TimeZone; } /** * Address data. */ export interface Address { /** * First line of address. Max length 64 bytes or 30 characters. */ address1?: string; /** * Second line of address. Max length 64 bytes or 30 characters. */ address2?: string; /** * City. Max length 60 bytes or 30 characters. */ city?: string; /** * Name of the company. Max length 255 bytes or 34 characters. */ company?: string; /** * Contact name of the company. Max length 128 bytes or 34 characters. */ contact?: string; /** * Fax number with international code (i.e. +441234567890). */ fax?: string; /** * Phone number with international code (i.e. +441234567890). */ phone?: string; /** * Country/Region code. The region is specified as a CLDR region code (e.g. * "US", "FR"). */ regionCode?: string; /** * State. Max length 60 bytes or 30 characters. */ state?: string; /** * Zip/post code. Max length 10 bytes or 10 characters. */ zip?: string; } /** * Request definition for the account close rpc. */ export interface CloseAccountRequest { } /** * Response definition for the account close rpc. */ export interface CloseAccountResponse { } /** * A generic empty message that you can re-use to avoid defining duplicated * empty messages in your APIs. A typical example is to use it as the request or * the response type of an API method. For instance: service Foo { rpc * Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } */ export interface Empty { } /** * A platform sub-account event to record spam signals. */ export interface Event { /** * Required. Information associated with the event. */ eventInfo?: EventInfo; /** * Required. Event timestamp. */ eventTime?: Date; /** * Required. Event type. */ eventType?: | "EVENT_TYPE_UNSPECIFIED" | "LOG_IN_VIA_PLATFORM" | "SIGN_UP_VIA_PLATFORM"; } function serializeEvent(data: any): Event { return { ...data, eventTime: data["eventTime"] !== undefined ? data["eventTime"].toISOString() : undefined, }; } function deserializeEvent(data: any): Event { return { ...data, eventTime: data["eventTime"] !== undefined ? new Date(data["eventTime"]) : undefined, }; } /** * Private information for partner recorded events (PII). */ export interface EventInfo { /** * The billing address of the publisher associated with this event, if * available. */ billingAddress?: Address; /** * Required. The email address that is associated with the publisher when * performing the event. */ email?: string; } /** * Response definition for the list accounts rpc. */ export interface ListAccountsResponse { /** * The Accounts returned in the list response. Represented by a partial view * of the Account resource, populating `name` and `creation_request_id`. */ accounts?: Account[]; /** * Continuation token used to page through accounts. To retrieve the next * page of the results, set the next request's "page_token" value to this. */ nextPageToken?: string; } /** * Response definition for the site list rpc. */ export interface ListSitesResponse { /** * Continuation token used to page through sites. To retrieve the next page * of the results, set the next request's "page_token" value to this. */ nextPageToken?: string; /** * The sites returned in this list response. */ sites?: Site[]; } /** * Response definition for the lookup account rpc. */ export interface LookupAccountResponse { /** * The name of the Account Format: platforms/{platform}/accounts/{account_id} */ name?: string; } /** * Additional options for AdSensePlatform#platformsAccountsList. */ export interface PlatformsAccountsListOptions { /** * Optional. The maximum number of accounts to include in the response, used * for paging. If unspecified, at most 10000 accounts will be returned. The * maximum value is 10000; values above 10000 will be coerced to 10000. */ pageSize?: number; /** * Optional. A page token, received from a previous `ListAccounts` call. * Provide this to retrieve the subsequent page. */ pageToken?: string; } /** * Additional options for AdSensePlatform#platformsAccountsLookup. */ export interface PlatformsAccountsLookupOptions { /** * Optional. The creation_request_id provided when calling createAccount. */ creationRequestId?: string; } /** * Additional options for AdSensePlatform#platformsAccountsSitesList. */ export interface PlatformsAccountsSitesListOptions { /** * The maximum number of sites to include in the response, used for paging. * If unspecified, at most 10000 sites will be returned. The maximum value is * 10000; values above 10000 will be coerced to 10000. */ pageSize?: number; /** * A page token, received from a previous `ListSites` call. Provide this to * retrieve the subsequent page. When paginating, all other parameters * provided to `ListSites` must match the call that provided the page token. */ pageToken?: string; } /** * Response definition for the site request review rpc. */ export interface RequestSiteReviewResponse { } /** * Representation of a Site. */ export interface Site { /** * Domain/sub-domain of the site. Must be a valid domain complying with [RFC * 1035](https://www.ietf.org/rfc/rfc1035.txt) and formatted as punycode [RFC * 3492](https://www.ietf.org/rfc/rfc3492.txt) in case the domain contains * unicode characters. */ domain?: string; /** * Output only. Resource name of a site. Format: * platforms/{platform}/accounts/{account}/sites/{site} */ readonly name?: string; /** * Output only. State of a site. */ readonly state?: | "STATE_UNSPECIFIED" | "REQUIRES_REVIEW" | "GETTING_READY" | "READY" | "NEEDS_ATTENTION"; } /** * Represents a time zone from the [IANA Time Zone * Database](https://www.iana.org/time-zones). */ export interface TimeZone { /** * IANA Time Zone Database time zone. For example "America/New_York". */ id?: string; /** * Optional. IANA Time Zone Database version number. For example "2019a". */ version?: string; }