diff --git a/docs/content/2.client/22.user/00.index.md b/docs/content/2.client/22.user/00.index.md new file mode 100644 index 0000000..cf467cf --- /dev/null +++ b/docs/content/2.client/22.user/00.index.md @@ -0,0 +1,50 @@ +--- +title: User +description: "User endpoint reference." +navigation: + title: User +--- + +## Get + +Retrieves detailed information about the currently authenticated user, including email, name, and account memberships. + +```php [php] +$response = $client->user()->get(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-user-details"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Edit part of your user details. + +::params-table +--- +params: + - name: "values" + type: "array" + required: false + description: "User values, e.g. first_name, last_name, telephone, country, zipcode." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->update([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-edit-user"} +View this operation on the Cloudflare API Reference +:: + +## Related + +- [Audit Logs](/client/user/audit-logs) +- [Invites](/client/user/invites) +- [Subscriptions](/client/user/subscriptions) +- [Tenants](/client/user/tenants) +- [Tokens](/client/user/tokens) + diff --git a/docs/content/2.client/22.user/01.audit-logs.md b/docs/content/2.client/22.user/01.audit-logs.md new file mode 100644 index 0000000..1e0ae81 --- /dev/null +++ b/docs/content/2.client/22.user/01.audit-logs.md @@ -0,0 +1,30 @@ +--- +title: Audit Logs +description: "Audit Logs endpoint reference." +navigation: + title: Audit Logs +--- + +## List + +Gets a list of audit logs for a user account. Can be filtered by who made the change, on which zone, and the timeframe of the change. + +::params-table +--- +params: + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->auditLogs()->list([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/audit-logs-get-user-audit-logs"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/22.user/02.invites.md b/docs/content/2.client/22.user/02.invites.md new file mode 100644 index 0000000..829fd7d --- /dev/null +++ b/docs/content/2.client/22.user/02.invites.md @@ -0,0 +1,67 @@ +--- +title: Invites +description: "Invites endpoint reference." +navigation: + title: Invites +--- + +## List + +Lists all invitations associated with my user. + +```php [php] +$response = $client->user()->invites()->list(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-invites-list-invitations"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Gets the details of an invitation. + +::params-table +--- +params: + - name: "inviteId" + type: "string" + required: true + description: "Invite identifier tag." +--- +:: + +```php [php] +$response = $client->user()->invites()->get('INVITE_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-invites-invitation-details"} +View this operation on the Cloudflare API Reference +:: + +## Respond + +Responds to an invitation. + +::params-table +--- +params: + - name: "inviteId" + type: "string" + required: true + description: "Invite identifier tag." + - name: "status" + type: "string" + required: true + description: "Status of the invitation, e.g. accepted, rejected." +--- +:: + +```php [php] +$response = $client->user()->invites()->respond('INVITE_ID', 'STATUS'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-invites-respond-to-invitation"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/22.user/03.subscriptions.md b/docs/content/2.client/22.user/03.subscriptions.md new file mode 100644 index 0000000..ff86006 --- /dev/null +++ b/docs/content/2.client/22.user/03.subscriptions.md @@ -0,0 +1,91 @@ +--- +title: Subscriptions +description: "Subscriptions endpoint reference." +navigation: + title: Subscriptions +--- + +## List + +Lists all of a user's subscriptions. + +```php [php] +$response = $client->user()->subscriptions()->list(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-subscription-get-user-subscriptions"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Creates a user subscription. + +::params-table +--- +params: + - name: "values" + type: "array" + required: false + description: "Subscription values, e.g. frequency, rate_plan." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->subscriptions()->create([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-subscription-create-user-subscription"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Updates a user's subscription. + +::params-table +--- +params: + - name: "subscriptionId" + type: "string" + required: true + description: "Subscription identifier tag." + - name: "values" + type: "array" + required: false + description: "Subscription values, e.g. frequency, rate_plan." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->subscriptions()->update('SUBSCRIPTION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-subscription-update-user-subscription"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Deletes a user's subscription. + +::params-table +--- +params: + - name: "subscriptionId" + type: "string" + required: true + description: "Subscription identifier tag." +--- +:: + +```php [php] +$response = $client->user()->subscriptions()->delete('SUBSCRIPTION_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-subscription-delete-user-subscription"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/22.user/04.tenants.md b/docs/content/2.client/22.user/04.tenants.md new file mode 100644 index 0000000..d55f428 --- /dev/null +++ b/docs/content/2.client/22.user/04.tenants.md @@ -0,0 +1,19 @@ +--- +title: Tenants +description: "Tenants endpoint reference." +navigation: + title: Tenants +--- + +## List + +Retrieves list of tenants the authenticated user has access to. + +```php [php] +$response = $client->user()->tenants()->list(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/User_listUserTenants"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/22.user/05.tokens/00.index.md b/docs/content/2.client/22.user/05.tokens/00.index.md new file mode 100644 index 0000000..03d4568 --- /dev/null +++ b/docs/content/2.client/22.user/05.tokens/00.index.md @@ -0,0 +1,139 @@ +--- +title: Tokens +description: "Tokens endpoint reference." +navigation: + title: Tokens +--- + +## List + +List all API tokens created for this user. + +::params-table +--- +params: + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->tokens()->list([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-list-tokens"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Create a new API token. + +::params-table +--- +params: + - name: "values" + type: "array" + required: true + description: "Token values, requires name and policies." +--- +:: + +```php [php] +$response = $client->user()->tokens()->create([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-create-token"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific API token. + +::params-table +--- +params: + - name: "tokenId" + type: "string" + required: true + description: "Token identifier." +--- +:: + +```php [php] +$response = $client->user()->tokens()->get('TOKEN_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-token-details"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Update an existing token. + +::params-table +--- +params: + - name: "tokenId" + type: "string" + required: true + description: "Token identifier." + - name: "values" + type: "array" + required: true + description: "Token values, e.g. name, policies, condition, status." +--- +:: + +```php [php] +$response = $client->user()->tokens()->update('TOKEN_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-update-token"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Destroy an API token. + +::params-table +--- +params: + - name: "tokenId" + type: "string" + required: true + description: "Token identifier." +--- +:: + +```php [php] +$response = $client->user()->tokens()->delete('TOKEN_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-delete-token"} +View this operation on the Cloudflare API Reference +:: + +## Verify + +Test whether a token works. + +```php [php] +$response = $client->user()->tokens()->verify(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-verify-token"} +View this operation on the Cloudflare API Reference +:: + +## Related + +- [Permission Groups](/client/user/tokens/permission-groups) +- [Value](/client/user/tokens/value) + diff --git a/docs/content/2.client/22.user/05.tokens/01.permission-groups.md b/docs/content/2.client/22.user/05.tokens/01.permission-groups.md new file mode 100644 index 0000000..7ed11e6 --- /dev/null +++ b/docs/content/2.client/22.user/05.tokens/01.permission-groups.md @@ -0,0 +1,30 @@ +--- +title: Permission Groups +description: "Permission Groups endpoint reference." +navigation: + title: Permission Groups +--- + +## List + +Find all available permission groups for API Tokens. + +::params-table +--- +params: + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. name, scope." + default: "[]" +--- +:: + +```php [php] +$response = $client->user()->tokens()->permissionGroups()->list([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/permission-groups-list-permission-groups"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/22.user/05.tokens/02.value.md b/docs/content/2.client/22.user/05.tokens/02.value.md new file mode 100644 index 0000000..5fa0601 --- /dev/null +++ b/docs/content/2.client/22.user/05.tokens/02.value.md @@ -0,0 +1,29 @@ +--- +title: Value +description: "Value endpoint reference." +navigation: + title: Value +--- + +## Roll + +Roll the API token secret. + +::params-table +--- +params: + - name: "tokenId" + type: "string" + required: true + description: "Token identifier." +--- +:: + +```php [php] +$response = $client->user()->tokens()->value()->roll('TOKEN_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user-api-tokens-roll-token"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/23.organizations/00.index.md b/docs/content/2.client/23.organizations/00.index.md new file mode 100644 index 0000000..8be64f9 --- /dev/null +++ b/docs/content/2.client/23.organizations/00.index.md @@ -0,0 +1,130 @@ +--- +title: Organizations +description: "Organizations endpoint reference." +navigation: + title: Organizations +--- + +## List + +Retrieve a list of organizations a particular user has access to. + +::params-table +--- +params: + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->list([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organization_listOrganizations"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Create a new organization for a user. + +::params-table +--- +params: + - name: "values" + type: "array" + required: true + description: "Organization values, requires name." +--- +:: + +```php [php] +$response = $client->organizations()->create([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_createUserOrganization"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Retrieve the details of a certain organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." +--- +:: + +```php [php] +$response = $client->organizations()->get('ORGANIZATION_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_retrieve"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Modify organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "values" + type: "array" + required: false + description: "Organization values, e.g. name." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->update('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_modify"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Delete an organization. The organization MUST be empty before deleting. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." +--- +:: + +```php [php] +$response = $client->organizations()->delete('ORGANIZATION_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_delete"} +View this operation on the Cloudflare API Reference +:: + +## Related + +- [Profile](/client/organizations/profile) +- [Logs](/client/organizations/logs) +- [Billing](/client/organizations/billing) +- [Members](/client/organizations/members) + diff --git a/docs/content/2.client/23.organizations/01.profile.md b/docs/content/2.client/23.organizations/01.profile.md new file mode 100644 index 0000000..1feb0b0 --- /dev/null +++ b/docs/content/2.client/23.organizations/01.profile.md @@ -0,0 +1,55 @@ +--- +title: Profile +description: "Profile endpoint reference." +navigation: + title: Profile +--- + +## Get + +Get an organizations profile if it exists. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." +--- +:: + +```php [php] +$response = $client->organizations()->profile()->get('ORGANIZATION_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_getProfile"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Modify organization profile. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "values" + type: "array" + required: true + description: "Profile values, requires business_name, business_email, business_phone, business_address and external_metadata." +--- +:: + +```php [php] +$response = $client->organizations()->profile()->update('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Organizations_modifyProfile"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/23.organizations/02.logs/00.index.md b/docs/content/2.client/23.organizations/02.logs/00.index.md new file mode 100644 index 0000000..1a8df4c --- /dev/null +++ b/docs/content/2.client/23.organizations/02.logs/00.index.md @@ -0,0 +1,11 @@ +--- +title: Logs +description: "Logs endpoint reference." +navigation: + title: Logs +--- + +## Related + +- [Audit](/client/organizations/logs/audit) + diff --git a/docs/content/2.client/23.organizations/02.logs/01.audit.md b/docs/content/2.client/23.organizations/02.logs/01.audit.md new file mode 100644 index 0000000..7159ff8 --- /dev/null +++ b/docs/content/2.client/23.organizations/02.logs/01.audit.md @@ -0,0 +1,65 @@ +--- +title: Audit +description: "Audit endpoint reference." +navigation: + title: Audit +--- + +## List + +Gets a list of audit logs for an organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, requires since and before." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->logs()->audit()->list('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/audit-logs-v2-get-organization-audit-logs"} +View this operation on the Cloudflare API Reference +:: + +## History + +Returns the chronological change history for the resource identified by the given organization-scoped audit log entry. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "id" + type: "string" + required: true + description: "Audit log entry identifier used to locate the resource." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, requires action_time, since and before." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->logs()->audit()->history('ORGANIZATION_ID', 'ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/audit-logs-v2-get-organization-audit-log-history"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/23.organizations/03.billing/00.index.md b/docs/content/2.client/23.organizations/03.billing/00.index.md new file mode 100644 index 0000000..c668a6a --- /dev/null +++ b/docs/content/2.client/23.organizations/03.billing/00.index.md @@ -0,0 +1,11 @@ +--- +title: Billing +description: "Billing endpoint reference." +navigation: + title: Billing +--- + +## Related + +- [Usage](/client/organizations/billing/usage) + diff --git a/docs/content/2.client/23.organizations/03.billing/01.usage.md b/docs/content/2.client/23.organizations/03.billing/01.usage.md new file mode 100644 index 0000000..aa2b67c --- /dev/null +++ b/docs/content/2.client/23.organizations/03.billing/01.usage.md @@ -0,0 +1,34 @@ +--- +title: Usage +description: "Usage endpoint reference." +navigation: + title: Usage +--- + +## Get + +Returns cost and usage data for all accounts within an organization, aligned with the FinOps FOCUS v1.3 Cost and Usage dataset specification. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. from, to." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->billing()->usage()->get('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/billable-usage-v2-get-organization-usage"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/23.organizations/04.members.md b/docs/content/2.client/23.organizations/04.members.md new file mode 100644 index 0000000..72a3668 --- /dev/null +++ b/docs/content/2.client/23.organizations/04.members.md @@ -0,0 +1,138 @@ +--- +title: Members +description: "Members endpoint reference." +navigation: + title: Members +--- + +## List + +List members of an organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. status, user.email." + default: "[]" +--- +:: + +```php [php] +$response = $client->organizations()->members()->list('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Members_list"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Add a member to an organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "values" + type: "array" + required: true + description: "Values, requires member." +--- +:: + +```php [php] +$response = $client->organizations()->members()->create('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Members_create"} +View this operation on the Cloudflare API Reference +:: + +## Batch Create + +Add multiple members to an organization in a single request. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "values" + type: "array" + required: true + description: "Values, requires members." +--- +:: + +```php [php] +$response = $client->organizations()->members()->batchCreate('ORGANIZATION_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Members_batchCreate"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific member of an organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "memberId" + type: "string" + required: true + description: "Member identifier." +--- +:: + +```php [php] +$response = $client->organizations()->members()->get('ORGANIZATION_ID', 'MEMBER_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Members_retrieve"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Remove a member from an organization. + +::params-table +--- +params: + - name: "organizationId" + type: "string" + required: true + description: "Organization identifier." + - name: "memberId" + type: "string" + required: true + description: "Member identifier." +--- +:: + +```php [php] +$response = $client->organizations()->members()->delete('ORGANIZATION_ID', 'MEMBER_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Members_delete"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/24.memberships.md b/docs/content/2.client/24.memberships.md new file mode 100644 index 0000000..6ab0bcd --- /dev/null +++ b/docs/content/2.client/24.memberships.md @@ -0,0 +1,100 @@ +--- +title: Memberships +description: "Memberships endpoint reference." +navigation: + title: Memberships +--- + +## List + +List memberships of accounts the user can access. + +::params-table +--- +params: + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params." + default: "[]" +--- +:: + +```php [php] +$response = $client->memberships()->list([]); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-account-memberships-list-memberships"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get a specific membership. + +::params-table +--- +params: + - name: "membershipId" + type: "string" + required: true + description: "Membership identifier tag." +--- +:: + +```php [php] +$response = $client->memberships()->get('MEMBERSHIP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-account-memberships-membership-details"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Accept or reject this account invitation. + +::params-table +--- +params: + - name: "membershipId" + type: "string" + required: true + description: "Membership identifier tag." + - name: "status" + type: "string" + required: true + description: "Status of this membership, e.g. accepted, rejected." +--- +:: + +```php [php] +$response = $client->memberships()->update('MEMBERSHIP_ID', 'STATUS'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-account-memberships-update-membership"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Remove the associated member from an account. + +::params-table +--- +params: + - name: "membershipId" + type: "string" + required: true + description: "Membership identifier tag." +--- +:: + +```php [php] +$response = $client->memberships()->delete('MEMBERSHIP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/user's-account-memberships-delete-membership"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/25.tenants/00.index.md b/docs/content/2.client/25.tenants/00.index.md new file mode 100644 index 0000000..bea93bb --- /dev/null +++ b/docs/content/2.client/25.tenants/00.index.md @@ -0,0 +1,36 @@ +--- +title: Tenants +description: "Tenants endpoint reference." +navigation: + title: Tenants +--- + +## Get + +Retrieves a Tenant by Tenant ID. + +::params-table +--- +params: + - name: "tenantId" + type: "string" + required: true + description: "Tenant identifier." +--- +:: + +```php [php] +$response = $client->tenants()->get('TENANT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Tenants_retrieveTenant"} +View this operation on the Cloudflare API Reference +:: + +## Related + +- [Account Types](/client/tenants/account-types) +- [Accounts](/client/tenants/accounts) +- [Entitlements](/client/tenants/entitlements) +- [Memberships](/client/tenants/memberships) + diff --git a/docs/content/2.client/25.tenants/01.account-types.md b/docs/content/2.client/25.tenants/01.account-types.md new file mode 100644 index 0000000..a347b9e --- /dev/null +++ b/docs/content/2.client/25.tenants/01.account-types.md @@ -0,0 +1,29 @@ +--- +title: Account Types +description: "Account Types endpoint reference." +navigation: + title: Account Types +--- + +## List + +List of account types available for the Tenant to provision accounts. + +::params-table +--- +params: + - name: "tenantId" + type: "string" + required: true + description: "Tenant identifier." +--- +:: + +```php [php] +$response = $client->tenants()->accountTypes()->list('TENANT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Tenants_validAccountTypes"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/25.tenants/02.accounts.md b/docs/content/2.client/25.tenants/02.accounts.md new file mode 100644 index 0000000..d20aa45 --- /dev/null +++ b/docs/content/2.client/25.tenants/02.accounts.md @@ -0,0 +1,29 @@ +--- +title: Accounts +description: "Accounts endpoint reference." +navigation: + title: Accounts +--- + +## List + +List of accounts for the Tenant. + +::params-table +--- +params: + - name: "tenantId" + type: "string" + required: true + description: "Tenant identifier." +--- +:: + +```php [php] +$response = $client->tenants()->accounts()->list('TENANT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Tenants_listAccounts"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/25.tenants/03.entitlements.md b/docs/content/2.client/25.tenants/03.entitlements.md new file mode 100644 index 0000000..3fd7b45 --- /dev/null +++ b/docs/content/2.client/25.tenants/03.entitlements.md @@ -0,0 +1,29 @@ +--- +title: Entitlements +description: "Entitlements endpoint reference." +navigation: + title: Entitlements +--- + +## Get + +List of innate entitlements available for the Tenant. + +::params-table +--- +params: + - name: "tenantId" + type: "string" + required: true + description: "Tenant identifier." +--- +:: + +```php [php] +$response = $client->tenants()->entitlements()->get('TENANT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Tenants_listEntitlements"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/25.tenants/04.memberships.md b/docs/content/2.client/25.tenants/04.memberships.md new file mode 100644 index 0000000..5b7970f --- /dev/null +++ b/docs/content/2.client/25.tenants/04.memberships.md @@ -0,0 +1,29 @@ +--- +title: Memberships +description: "Memberships endpoint reference." +navigation: + title: Memberships +--- + +## List + +List of active members (Cloudflare users) for the Tenant. + +::params-table +--- +params: + - name: "tenantId" + type: "string" + required: true + description: "Tenant identifier." +--- +:: + +```php [php] +$response = $client->tenants()->memberships()->list('TENANT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/Tenants_listMemberships"} +View this operation on the Cloudflare API Reference +:: + diff --git a/src/Client.php b/src/Client.php index 7724d2f..af98e94 100644 --- a/src/Client.php +++ b/src/Client.php @@ -32,6 +32,10 @@ * @method \Cloudflare\Endpoints\CloudConnector cloudConnector() * @method \Cloudflare\Endpoints\R2 r2() * @method \Cloudflare\Endpoints\Iam iam() + * @method \Cloudflare\Endpoints\User user() + * @method \Cloudflare\Endpoints\Organizations organizations() + * @method \Cloudflare\Endpoints\Memberships memberships() + * @method \Cloudflare\Endpoints\Tenants tenants() * * @author Sergkei Melingk * @@ -98,6 +102,10 @@ public function api(string $name): AbstractEndpoint 'cloudConnector' => new Endpoints\CloudConnector($this), 'r2' => new Endpoints\R2($this), 'iam' => new Endpoints\Iam($this), + 'user' => new Endpoints\User($this), + 'organizations' => new Endpoints\Organizations($this), + 'memberships' => new Endpoints\Memberships($this), + 'tenants' => new Endpoints\Tenants($this), default => throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)) }; diff --git a/src/Endpoints/Memberships.php b/src/Endpoints/Memberships.php new file mode 100644 index 0000000..c94760d --- /dev/null +++ b/src/Endpoints/Memberships.php @@ -0,0 +1,67 @@ +getHttpClient()->get('/memberships', $params); + } + + /** + * Get a specific membership. + * + * @link https://developers.cloudflare.com/api/operations/user's-account-memberships-membership-details + * + * @param string $membershipId Membership identifier tag. + * + * @return ResponseInterface Membership Details response. + */ + public function get(string $membershipId): ResponseInterface + { + return $this->getHttpClient()->get("/memberships/{$membershipId}"); + } + + /** + * Accept or reject this account invitation. + * + * @link https://developers.cloudflare.com/api/operations/user's-account-memberships-update-membership + * + * @param string $membershipId Membership identifier tag. + * @param string $status Status of this membership, e.g. accepted, rejected. + * + * @return ResponseInterface Update Membership response. + */ + public function update(string $membershipId, string $status): ResponseInterface + { + return $this->getHttpClient()->put("/memberships/{$membershipId}", [ + 'status' => $status, + ]); + } + + /** + * Remove the associated member from an account. + * + * @link https://developers.cloudflare.com/api/operations/user's-account-memberships-delete-membership + * + * @param string $membershipId Membership identifier tag. + * + * @return ResponseInterface Delete Membership response. + */ + public function delete(string $membershipId): ResponseInterface + { + return $this->getHttpClient()->delete("/memberships/{$membershipId}"); + } +} diff --git a/src/Endpoints/Organizations.php b/src/Endpoints/Organizations.php new file mode 100644 index 0000000..413b491 --- /dev/null +++ b/src/Endpoints/Organizations.php @@ -0,0 +1,128 @@ +getHttpClient()->get('/organizations', $params); + } + + /** + * Create a new organization for a user. + * + * @link https://developers.cloudflare.com/api/operations/Organizations_createUserOrganization + * + * @param array $values Organization values, requires name. + * + * @return ResponseInterface Create Organization response. + */ + public function create(array $values): ResponseInterface + { + $this->requiredParams(['name'], $values); + + return $this->getHttpClient()->post('/organizations', $values); + } + + /** + * Retrieve the details of a certain organization. + * + * @link https://developers.cloudflare.com/api/operations/Organizations_retrieve + * + * @param string $organizationId Organization identifier. + * + * @return ResponseInterface Organization Details response. + */ + public function get(string $organizationId): ResponseInterface + { + return $this->getHttpClient()->get("/organizations/{$organizationId}"); + } + + /** + * Modify organization. + * + * @link https://developers.cloudflare.com/api/operations/Organizations_modify + * + * @param string $organizationId Organization identifier. + * @param array $values Organization values, e.g. name. + * + * @return ResponseInterface Update Organization response. + */ + public function update(string $organizationId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->put("/organizations/{$organizationId}", $values); + } + + /** + * Delete an organization. The organization MUST be empty before deleting. + * + * @link https://developers.cloudflare.com/api/operations/Organizations_delete + * + * @param string $organizationId Organization identifier. + * + * @return ResponseInterface Delete Organization response. + */ + public function delete(string $organizationId): ResponseInterface + { + return $this->getHttpClient()->delete("/organizations/{$organizationId}"); + } + + /** + * Organization Profile + * + * @return \Cloudflare\Endpoints\Organizations\Profile + */ + public function profile(): Profile + { + return new Profile($this->getClient()); + } + + /** + * Organization Logs + * + * @return \Cloudflare\Endpoints\Organizations\Logs + */ + public function logs(): Logs + { + return new Logs($this->getClient()); + } + + /** + * Organization Billing + * + * @return \Cloudflare\Endpoints\Organizations\Billing + */ + public function billing(): Billing + { + return new Billing($this->getClient()); + } + + /** + * Organization Members + * + * @return \Cloudflare\Endpoints\Organizations\Members + */ + public function members(): Members + { + return new Members($this->getClient()); + } +} diff --git a/src/Endpoints/Organizations/Billing.php b/src/Endpoints/Organizations/Billing.php new file mode 100644 index 0000000..4d3addd --- /dev/null +++ b/src/Endpoints/Organizations/Billing.php @@ -0,0 +1,19 @@ +getClient()); + } +} diff --git a/src/Endpoints/Organizations/Billing/Usage.php b/src/Endpoints/Organizations/Billing/Usage.php new file mode 100644 index 0000000..66f8d68 --- /dev/null +++ b/src/Endpoints/Organizations/Billing/Usage.php @@ -0,0 +1,24 @@ +getHttpClient()->get("/organizations/{$organizationId}/billable/usage", $params); + } +} diff --git a/src/Endpoints/Organizations/Logs.php b/src/Endpoints/Organizations/Logs.php new file mode 100644 index 0000000..4bf8e2c --- /dev/null +++ b/src/Endpoints/Organizations/Logs.php @@ -0,0 +1,19 @@ +getClient()); + } +} diff --git a/src/Endpoints/Organizations/Logs/Audit.php b/src/Endpoints/Organizations/Logs/Audit.php new file mode 100644 index 0000000..48a6cbe --- /dev/null +++ b/src/Endpoints/Organizations/Logs/Audit.php @@ -0,0 +1,44 @@ +requiredParams(['since', 'before'], $params); + + return $this->getHttpClient()->get("/organizations/{$organizationId}/logs/audit", $params); + } + + /** + * Returns the chronological change history for the resource identified by the given organization-scoped audit log entry. + * + * @link https://developers.cloudflare.com/api/operations/audit-logs-v2-get-organization-audit-log-history + * + * @param string $organizationId Organization identifier. + * @param string $id Audit log entry identifier used to locate the resource. + * @param array $params Array containing the necessary params, requires action_time, since and before. + * + * @return ResponseInterface Audit Log History response. + */ + public function history(string $organizationId, string $id, array $params = []): ResponseInterface + { + $this->requiredParams(['action_time', 'since', 'before'], $params); + + return $this->getHttpClient()->get("/organizations/{$organizationId}/logs/audit/{$id}/history", $params); + } +} diff --git a/src/Endpoints/Organizations/Members.php b/src/Endpoints/Organizations/Members.php new file mode 100644 index 0000000..0cb4507 --- /dev/null +++ b/src/Endpoints/Organizations/Members.php @@ -0,0 +1,90 @@ +getHttpClient()->get("/organizations/{$organizationId}/members", $params); + } + + /** + * Add a member to an organization. + * + * @link https://developers.cloudflare.com/api/operations/Members_create + * + * @param string $organizationId Organization identifier. + * @param array $values Values, requires member. + * + * @return ResponseInterface Create Member response. + */ + public function create(string $organizationId, array $values): ResponseInterface + { + $this->requiredParams(['member'], $values); + + return $this->getHttpClient()->post("/organizations/{$organizationId}/members", $values); + } + + /** + * Add multiple members to an organization in a single request. + * + * @link https://developers.cloudflare.com/api/operations/Members_batchCreate + * + * @param string $organizationId Organization identifier. + * @param array $values Values, requires members. + * + * @return ResponseInterface Batch Create Members response. + */ + public function batchCreate(string $organizationId, array $values): ResponseInterface + { + $this->requiredParams(['members'], $values); + + return $this->getHttpClient()->post("/organizations/{$organizationId}/members:batchCreate", $values); + } + + /** + * Get information about a specific member of an organization. + * + * @link https://developers.cloudflare.com/api/operations/Members_retrieve + * + * @param string $organizationId Organization identifier. + * @param string $memberId Member identifier. + * + * @return ResponseInterface Member Details response. + */ + public function get(string $organizationId, string $memberId): ResponseInterface + { + return $this->getHttpClient()->get("/organizations/{$organizationId}/members/{$memberId}"); + } + + /** + * Remove a member from an organization. + * + * @link https://developers.cloudflare.com/api/operations/Members_delete + * + * @param string $organizationId Organization identifier. + * @param string $memberId Member identifier. + * + * @return ResponseInterface Delete Member response. + */ + public function delete(string $organizationId, string $memberId): ResponseInterface + { + return $this->getHttpClient()->delete("/organizations/{$organizationId}/members/{$memberId}", [ + 'member_id' => $memberId, + ]); + } +} diff --git a/src/Endpoints/Organizations/Profile.php b/src/Endpoints/Organizations/Profile.php new file mode 100644 index 0000000..02870cd --- /dev/null +++ b/src/Endpoints/Organizations/Profile.php @@ -0,0 +1,46 @@ +getHttpClient()->get("/organizations/{$organizationId}/profile"); + } + + /** + * Modify organization profile. + * + * @link https://developers.cloudflare.com/api/operations/Organizations_modifyProfile + * + * @param string $organizationId Organization identifier. + * @param array $values Profile values, requires business_name, business_email, business_phone, business_address and external_metadata. + * + * @return ResponseInterface Update Organization Profile response. + */ + public function update(string $organizationId, array $values): ResponseInterface + { + $this->requiredParams([ + 'business_name', + 'business_email', + 'business_phone', + 'business_address', + 'external_metadata', + ], $values); + + return $this->getHttpClient()->put("/organizations/{$organizationId}/profile", $values); + } +} diff --git a/src/Endpoints/Tenants.php b/src/Endpoints/Tenants.php new file mode 100644 index 0000000..4d14c1a --- /dev/null +++ b/src/Endpoints/Tenants.php @@ -0,0 +1,66 @@ +getHttpClient()->get("/tenants/{$tenantId}"); + } + + /** + * Tenant Account Types + * + * @return \Cloudflare\Endpoints\Tenants\AccountTypes + */ + public function accountTypes(): AccountTypes + { + return new AccountTypes($this->getClient()); + } + + /** + * Tenant Accounts + * + * @return \Cloudflare\Endpoints\Tenants\Accounts + */ + public function accounts(): Accounts + { + return new Accounts($this->getClient()); + } + + /** + * Tenant Entitlements + * + * @return \Cloudflare\Endpoints\Tenants\Entitlements + */ + public function entitlements(): Entitlements + { + return new Entitlements($this->getClient()); + } + + /** + * Tenant Memberships + * + * @return \Cloudflare\Endpoints\Tenants\Memberships + */ + public function memberships(): Memberships + { + return new Memberships($this->getClient()); + } +} diff --git a/src/Endpoints/Tenants/AccountTypes.php b/src/Endpoints/Tenants/AccountTypes.php new file mode 100644 index 0000000..dface9c --- /dev/null +++ b/src/Endpoints/Tenants/AccountTypes.php @@ -0,0 +1,23 @@ +getHttpClient()->get("/tenants/{$tenantId}/account_types"); + } +} diff --git a/src/Endpoints/Tenants/Accounts.php b/src/Endpoints/Tenants/Accounts.php new file mode 100644 index 0000000..3ddb698 --- /dev/null +++ b/src/Endpoints/Tenants/Accounts.php @@ -0,0 +1,23 @@ +getHttpClient()->get("/tenants/{$tenantId}/accounts"); + } +} diff --git a/src/Endpoints/Tenants/Entitlements.php b/src/Endpoints/Tenants/Entitlements.php new file mode 100644 index 0000000..eb565c1 --- /dev/null +++ b/src/Endpoints/Tenants/Entitlements.php @@ -0,0 +1,23 @@ +getHttpClient()->get("/tenants/{$tenantId}/entitlements"); + } +} diff --git a/src/Endpoints/Tenants/Memberships.php b/src/Endpoints/Tenants/Memberships.php new file mode 100644 index 0000000..0bfafe3 --- /dev/null +++ b/src/Endpoints/Tenants/Memberships.php @@ -0,0 +1,23 @@ +getHttpClient()->get("/tenants/{$tenantId}/memberships"); + } +} diff --git a/src/Endpoints/User.php b/src/Endpoints/User.php new file mode 100644 index 0000000..ebdaeba --- /dev/null +++ b/src/Endpoints/User.php @@ -0,0 +1,92 @@ +getHttpClient()->get('/user'); + } + + /** + * Edit part of your user details. + * + * @link https://developers.cloudflare.com/api/operations/user-edit-user + * + * @param array $values User values, e.g. first_name, last_name, telephone, country, zipcode. + * + * @return ResponseInterface Update User response. + */ + public function update(array $values = []): ResponseInterface + { + return $this->getHttpClient()->patch('/user', $values); + } + + /** + * User Audit Logs + * + * @return \Cloudflare\Endpoints\User\AuditLogs + */ + public function auditLogs(): AuditLogs + { + return new AuditLogs($this->getClient()); + } + + /** + * User Invites + * + * @return \Cloudflare\Endpoints\User\Invites + */ + public function invites(): Invites + { + return new Invites($this->getClient()); + } + + /** + * User Subscriptions + * + * @return \Cloudflare\Endpoints\User\Subscriptions + */ + public function subscriptions(): Subscriptions + { + return new Subscriptions($this->getClient()); + } + + /** + * User Tenants + * + * @return \Cloudflare\Endpoints\User\Tenants + */ + public function tenants(): Tenants + { + return new Tenants($this->getClient()); + } + + /** + * User API Tokens + * + * @return \Cloudflare\Endpoints\User\Tokens + */ + public function tokens(): Tokens + { + return new Tokens($this->getClient()); + } +} diff --git a/src/Endpoints/User/AuditLogs.php b/src/Endpoints/User/AuditLogs.php new file mode 100644 index 0000000..e80a69e --- /dev/null +++ b/src/Endpoints/User/AuditLogs.php @@ -0,0 +1,23 @@ +getHttpClient()->get('/user/audit_logs', $params); + } +} diff --git a/src/Endpoints/User/Invites.php b/src/Endpoints/User/Invites.php new file mode 100644 index 0000000..e969c6d --- /dev/null +++ b/src/Endpoints/User/Invites.php @@ -0,0 +1,52 @@ +getHttpClient()->get('/user/invites'); + } + + /** + * Gets the details of an invitation. + * + * @link https://developers.cloudflare.com/api/operations/user's-invites-invitation-details + * + * @param string $inviteId Invite identifier tag. + * + * @return ResponseInterface Invite Details response. + */ + public function get(string $inviteId): ResponseInterface + { + return $this->getHttpClient()->get("/user/invites/{$inviteId}"); + } + + /** + * Responds to an invitation. + * + * @link https://developers.cloudflare.com/api/operations/user's-invites-respond-to-invitation + * + * @param string $inviteId Invite identifier tag. + * @param string $status Status of the invitation, e.g. accepted, rejected. + * + * @return ResponseInterface Respond to Invite response. + */ + public function respond(string $inviteId, string $status): ResponseInterface + { + return $this->getHttpClient()->patch("/user/invites/{$inviteId}", [ + 'status' => $status, + ]); + } +} diff --git a/src/Endpoints/User/Subscriptions.php b/src/Endpoints/User/Subscriptions.php new file mode 100644 index 0000000..7f8b85f --- /dev/null +++ b/src/Endpoints/User/Subscriptions.php @@ -0,0 +1,64 @@ +getHttpClient()->get('/user/subscriptions'); + } + + /** + * Creates a user subscription. + * + * @link https://developers.cloudflare.com/api/operations/user-subscription-create-user-subscription + * + * @param array $values Subscription values, e.g. frequency, rate_plan. + * + * @return ResponseInterface Create Subscription response. + */ + public function create(array $values = []): ResponseInterface + { + return $this->getHttpClient()->post('/user/subscriptions', $values); + } + + /** + * Updates a user's subscription. + * + * @link https://developers.cloudflare.com/api/operations/user-subscription-update-user-subscription + * + * @param string $subscriptionId Subscription identifier tag. + * @param array $values Subscription values, e.g. frequency, rate_plan. + * + * @return ResponseInterface Update Subscription response. + */ + public function update(string $subscriptionId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->put("/user/subscriptions/{$subscriptionId}", $values); + } + + /** + * Deletes a user's subscription. + * + * @link https://developers.cloudflare.com/api/operations/user-subscription-delete-user-subscription + * + * @param string $subscriptionId Subscription identifier tag. + * + * @return ResponseInterface Delete Subscription response. + */ + public function delete(string $subscriptionId): ResponseInterface + { + return $this->getHttpClient()->delete("/user/subscriptions/{$subscriptionId}"); + } +} diff --git a/src/Endpoints/User/Tenants.php b/src/Endpoints/User/Tenants.php new file mode 100644 index 0000000..dadfc8c --- /dev/null +++ b/src/Endpoints/User/Tenants.php @@ -0,0 +1,21 @@ +getHttpClient()->get('/user/tenants'); + } +} diff --git a/src/Endpoints/User/Tokens.php b/src/Endpoints/User/Tokens.php new file mode 100644 index 0000000..c562ba7 --- /dev/null +++ b/src/Endpoints/User/Tokens.php @@ -0,0 +1,116 @@ +getHttpClient()->get('/user/tokens', $params); + } + + /** + * Create a new API token. + * + * @link https://developers.cloudflare.com/api/operations/user-api-tokens-create-token + * + * @param array $values Token values, requires name and policies. + * + * @return ResponseInterface Create Token response. + */ + public function create(array $values): ResponseInterface + { + $this->requiredParams(['name', 'policies'], $values); + + return $this->getHttpClient()->post('/user/tokens', $values); + } + + /** + * Get information about a specific API token. + * + * @link https://developers.cloudflare.com/api/operations/user-api-tokens-token-details + * + * @param string $tokenId Token identifier. + * + * @return ResponseInterface Token Details response. + */ + public function get(string $tokenId): ResponseInterface + { + return $this->getHttpClient()->get("/user/tokens/{$tokenId}"); + } + + /** + * Update an existing token. + * + * @link https://developers.cloudflare.com/api/operations/user-api-tokens-update-token + * + * @param string $tokenId Token identifier. + * @param array $values Token values, e.g. name, policies, condition, status. + * + * @return ResponseInterface Update Token response. + */ + public function update(string $tokenId, array $values): ResponseInterface + { + return $this->getHttpClient()->put("/user/tokens/{$tokenId}", $values); + } + + /** + * Destroy an API token. + * + * @link https://developers.cloudflare.com/api/operations/user-api-tokens-delete-token + * + * @param string $tokenId Token identifier. + * + * @return ResponseInterface Delete Token response. + */ + public function delete(string $tokenId): ResponseInterface + { + return $this->getHttpClient()->delete("/user/tokens/{$tokenId}"); + } + + /** + * Test whether a token works. + * + * @link https://developers.cloudflare.com/api/operations/user-api-tokens-verify-token + * + * @return ResponseInterface Verify Token response. + */ + public function verify(): ResponseInterface + { + return $this->getHttpClient()->get('/user/tokens/verify'); + } + + /** + * User API Token Permission Groups + * + * @return \Cloudflare\Endpoints\User\Tokens\PermissionGroups + */ + public function permissionGroups(): PermissionGroups + { + return new PermissionGroups($this->getClient()); + } + + /** + * User API Token Value + * + * @return \Cloudflare\Endpoints\User\Tokens\Value + */ + public function value(): Value + { + return new Value($this->getClient()); + } +} diff --git a/src/Endpoints/User/Tokens/PermissionGroups.php b/src/Endpoints/User/Tokens/PermissionGroups.php new file mode 100644 index 0000000..24cd471 --- /dev/null +++ b/src/Endpoints/User/Tokens/PermissionGroups.php @@ -0,0 +1,23 @@ +getHttpClient()->get('/user/tokens/permission_groups', $params); + } +} diff --git a/src/Endpoints/User/Tokens/Value.php b/src/Endpoints/User/Tokens/Value.php new file mode 100644 index 0000000..20de198 --- /dev/null +++ b/src/Endpoints/User/Tokens/Value.php @@ -0,0 +1,23 @@ +getHttpClient()->put("/user/tokens/{$tokenId}/value", []); + } +} diff --git a/test/Tests/Endpoints/MembershipsTest.php b/test/Tests/Endpoints/MembershipsTest.php new file mode 100644 index 0000000..adb161c --- /dev/null +++ b/test/Tests/Endpoints/MembershipsTest.php @@ -0,0 +1,70 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'membership_id']]])), + ]); + + $response = $client->memberships()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/memberships', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'membership_id']])), + ]); + + $response = $client->memberships()->get('membership_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/memberships/membership_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'membership_id']])), + ]); + + $response = $client->memberships()->update('membership_id', 'accepted'); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/memberships/membership_id', $this->lastRequest()->getUri()->getPath()); + $this->assertSame(['status' => 'accepted'], json_decode((string) $this->lastRequest()->getBody(), true)); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'membership_id']])), + ]); + + $response = $client->memberships()->delete('membership_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/memberships/membership_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Organizations/Billing/UsageTest.php b/test/Tests/Endpoints/Organizations/Billing/UsageTest.php new file mode 100644 index 0000000..bed84b5 --- /dev/null +++ b/test/Tests/Endpoints/Organizations/Billing/UsageTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => []])), + ]); + + $response = $client->organizations()->billing()->usage()->get('organization_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/billable/usage', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Organizations/Logs/AuditTest.php b/test/Tests/Endpoints/Organizations/Logs/AuditTest.php new file mode 100644 index 0000000..2c56d48 --- /dev/null +++ b/test/Tests/Endpoints/Organizations/Logs/AuditTest.php @@ -0,0 +1,58 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'audit_log_id']]])), + ]); + + $response = $client->organizations()->logs()->audit()->list('organization_id', [ + 'since' => '2024-10-30', + 'before' => '2024-10-31', + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/logs/audit', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenListParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->organizations()->logs()->audit()->list('organization_id'); + } + + #[Test] + public function shouldGetHistory() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'audit_log_id']]])), + ]); + + $response = $client->organizations()->logs()->audit()->history('organization_id', 'audit_log_id', [ + 'action_time' => '2024-10-30T15:00:00Z', + 'since' => '2024-10-30', + 'before' => '2024-10-31', + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/logs/audit/audit_log_id/history', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Organizations/MembersTest.php b/test/Tests/Endpoints/Organizations/MembersTest.php new file mode 100644 index 0000000..def608b --- /dev/null +++ b/test/Tests/Endpoints/Organizations/MembersTest.php @@ -0,0 +1,108 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'member_id']]])), + ]); + + $response = $client->organizations()->members()->list('organization_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/members', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'member_id']])), + ]); + + $response = $client->organizations()->members()->create('organization_id', [ + 'member' => ['user' => ['email' => 'user@example.com']], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/members', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->organizations()->members()->create('organization_id', []); + } + + #[Test] + public function shouldBatchCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'member_id']]])), + ]); + + $response = $client->organizations()->members()->batchCreate('organization_id', [ + 'members' => [['user' => ['email' => 'user@example.com']]], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/members:batchCreate', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenBatchCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->organizations()->members()->batchCreate('organization_id', []); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'member_id']])), + ]); + + $response = $client->organizations()->members()->get('organization_id', 'member_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/members/member_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'member_id']])), + ]); + + $response = $client->organizations()->members()->delete('organization_id', 'member_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/members/member_id', $this->lastRequest()->getUri()->getPath()); + $this->assertSame(['member_id' => 'member_id'], json_decode((string) $this->lastRequest()->getBody(), true)); + } +} diff --git a/test/Tests/Endpoints/Organizations/ProfileTest.php b/test/Tests/Endpoints/Organizations/ProfileTest.php new file mode 100644 index 0000000..35eb3f8 --- /dev/null +++ b/test/Tests/Endpoints/Organizations/ProfileTest.php @@ -0,0 +1,62 @@ + 'Acme Inc', + 'business_email' => 'billing@acme.example', + 'business_phone' => '+15555550100', + 'business_address' => '123 Main St', + 'external_metadata' => '{}', + ]; + } + + #[Test] + public function shouldGet() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['business_name' => 'Acme Inc']])), + ]); + + $response = $client->organizations()->profile()->get('organization_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/profile', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['business_name' => 'Acme Inc']])), + ]); + + $response = $client->organizations()->profile()->update('organization_id', $this->validValues()); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id/profile', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenUpdateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->organizations()->profile()->update('organization_id', ['business_name' => 'Acme Inc']); + } +} diff --git a/test/Tests/Endpoints/OrganizationsTest.php b/test/Tests/Endpoints/OrganizationsTest.php new file mode 100644 index 0000000..bc09698 --- /dev/null +++ b/test/Tests/Endpoints/OrganizationsTest.php @@ -0,0 +1,93 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'organization_id']]])), + ]); + + $response = $client->organizations()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'organization_id']])), + ]); + + $response = $client->organizations()->create(['name' => 'My Organization']); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->organizations()->create([]); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'organization_id']])), + ]); + + $response = $client->organizations()->get('organization_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'organization_id']])), + ]); + + $response = $client->organizations()->update('organization_id', ['name' => 'Renamed']); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'organization_id']])), + ]); + + $response = $client->organizations()->delete('organization_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/organizations/organization_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Tenants/AccountTypesTest.php b/test/Tests/Endpoints/Tenants/AccountTypesTest.php new file mode 100644 index 0000000..04d8a8d --- /dev/null +++ b/test/Tests/Endpoints/Tenants/AccountTypesTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['standard']])), + ]); + + $response = $client->tenants()->accountTypes()->list('tenant_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/tenants/tenant_id/account_types', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Tenants/AccountsTest.php b/test/Tests/Endpoints/Tenants/AccountsTest.php new file mode 100644 index 0000000..a2701ab --- /dev/null +++ b/test/Tests/Endpoints/Tenants/AccountsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'account_id']]])), + ]); + + $response = $client->tenants()->accounts()->list('tenant_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/tenants/tenant_id/accounts', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Tenants/EntitlementsTest.php b/test/Tests/Endpoints/Tenants/EntitlementsTest.php new file mode 100644 index 0000000..2c4f631 --- /dev/null +++ b/test/Tests/Endpoints/Tenants/EntitlementsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => []])), + ]); + + $response = $client->tenants()->entitlements()->get('tenant_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/tenants/tenant_id/entitlements', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Tenants/MembershipsTest.php b/test/Tests/Endpoints/Tenants/MembershipsTest.php new file mode 100644 index 0000000..c239d46 --- /dev/null +++ b/test/Tests/Endpoints/Tenants/MembershipsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['user_tag' => 'user_id']]])), + ]); + + $response = $client->tenants()->memberships()->list('tenant_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/tenants/tenant_id/memberships', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/TenantsTest.php b/test/Tests/Endpoints/TenantsTest.php new file mode 100644 index 0000000..c099b1f --- /dev/null +++ b/test/Tests/Endpoints/TenantsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['tenant_tag' => 'tenant_id']])), + ]); + + $response = $client->tenants()->get('tenant_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/tenants/tenant_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/AuditLogsTest.php b/test/Tests/Endpoints/User/AuditLogsTest.php new file mode 100644 index 0000000..6d28c8c --- /dev/null +++ b/test/Tests/Endpoints/User/AuditLogsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'audit_log_id']]])), + ]); + + $response = $client->user()->auditLogs()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/audit_logs', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/InvitesTest.php b/test/Tests/Endpoints/User/InvitesTest.php new file mode 100644 index 0000000..461a963 --- /dev/null +++ b/test/Tests/Endpoints/User/InvitesTest.php @@ -0,0 +1,56 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'invite_id']]])), + ]); + + $response = $client->user()->invites()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/invites', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'invite_id']])), + ]); + + $response = $client->user()->invites()->get('invite_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/invites/invite_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldRespond() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'invite_id']])), + ]); + + $response = $client->user()->invites()->respond('invite_id', 'accepted'); + + $this->assertTrue($response->successful()); + $this->assertSame('PATCH', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/invites/invite_id', $this->lastRequest()->getUri()->getPath()); + $this->assertSame(['status' => 'accepted'], json_decode((string) $this->lastRequest()->getBody(), true)); + } +} diff --git a/test/Tests/Endpoints/User/SubscriptionsTest.php b/test/Tests/Endpoints/User/SubscriptionsTest.php new file mode 100644 index 0000000..ef950f3 --- /dev/null +++ b/test/Tests/Endpoints/User/SubscriptionsTest.php @@ -0,0 +1,69 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'subscription_id']]])), + ]); + + $response = $client->user()->subscriptions()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/subscriptions', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'subscription_id']])), + ]); + + $response = $client->user()->subscriptions()->create(['frequency' => 'monthly']); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/subscriptions', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'subscription_id']])), + ]); + + $response = $client->user()->subscriptions()->update('subscription_id', ['frequency' => 'yearly']); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/subscriptions/subscription_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['subscription_id' => 'subscription_id']])), + ]); + + $response = $client->user()->subscriptions()->delete('subscription_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/subscriptions/subscription_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/TenantsTest.php b/test/Tests/Endpoints/User/TenantsTest.php new file mode 100644 index 0000000..38721db --- /dev/null +++ b/test/Tests/Endpoints/User/TenantsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'tenant_id']]])), + ]); + + $response = $client->user()->tenants()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tenants', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/Tokens/PermissionGroupsTest.php b/test/Tests/Endpoints/User/Tokens/PermissionGroupsTest.php new file mode 100644 index 0000000..19bddf0 --- /dev/null +++ b/test/Tests/Endpoints/User/Tokens/PermissionGroupsTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'permission_group_id']]])), + ]); + + $response = $client->user()->tokens()->permissionGroups()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/permission_groups', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/Tokens/ValueTest.php b/test/Tests/Endpoints/User/Tokens/ValueTest.php new file mode 100644 index 0000000..04a10fc --- /dev/null +++ b/test/Tests/Endpoints/User/Tokens/ValueTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['value' => 'new_token_secret']])), + ]); + + $response = $client->user()->tokens()->value()->roll('token_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/token_id/value', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/User/TokensTest.php b/test/Tests/Endpoints/User/TokensTest.php new file mode 100644 index 0000000..cd28165 --- /dev/null +++ b/test/Tests/Endpoints/User/TokensTest.php @@ -0,0 +1,110 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'token_id']]])), + ]); + + $response = $client->user()->tokens()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'token_id']])), + ]); + + $response = $client->user()->tokens()->create([ + 'name' => 'readonly token', + 'policies' => [['effect' => 'allow']], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->user()->tokens()->create(['name' => 'readonly token']); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'token_id']])), + ]); + + $response = $client->user()->tokens()->get('token_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/token_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'token_id']])), + ]); + + $response = $client->user()->tokens()->update('token_id', ['name' => 'renamed token']); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/token_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'token_id']])), + ]); + + $response = $client->user()->tokens()->delete('token_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/token_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldVerify() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'token_id', 'status' => 'active']])), + ]); + + $response = $client->user()->tokens()->verify(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user/tokens/verify', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/UserTest.php b/test/Tests/Endpoints/UserTest.php new file mode 100644 index 0000000..fa90137 --- /dev/null +++ b/test/Tests/Endpoints/UserTest.php @@ -0,0 +1,42 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_id']])), + ]); + + $response = $client->user()->get(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_id']])), + ]); + + $response = $client->user()->update(['first_name' => 'John']); + + $this->assertTrue($response->successful()); + $this->assertSame('PATCH', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/user', $this->lastRequest()->getUri()->getPath()); + $this->assertSame(['first_name' => 'John'], json_decode((string) $this->lastRequest()->getBody(), true)); + } +}